Question
PLEASE help me, give me the code and everything he want, THANK YOU!!!!!!!!!
Use MATLAB to compute the following expressions. For-loops will be useful in this exercise. Save your code in a ".m" file and upload to the Dropbox shared folder "ex1". To save your computed results to ".dat" files use the command "save ... -ascii". Compute the following expressions and save the result F(10) to Al.dat and the result F(100) to A2.dat". Consider the recurrence relation xn+2 = Xn + 1 + Xn with x1= 1, x2 = 1. Compute the number X1, X2, , x20 and save the results to A3.dat using a column-vector of length 20. Compute the golden ratio using the formula x20/x19 and save the result to A4.dat. In this exercise, write a MATLAB code to show that . Do this by creating a x vector x that has elements 1, 10-1, 10-2, 10-3, 10-4, 10-5.10-6. Then use the element-by- element operations to create a new vector y = ex-1/x . Save the vector x to VecX.dat . Save the vector y to VecY.dat Upload your ".m" file to the Dropbox shared folder "ex2". To save your computed results to ".dat" files use the command "save ... -ascii". Plot the function f(x) = 40/1+(X-4)2+ 5sin (20X/PI )in the domain 0 le x le 10. Please make sure you have sampled enough points for the plot. Print out the resulting figure and attach it to your homework. Turn in the code you used (or rewrite it on your homework).
Explanation / Answer
1) (a) first create a function
function y = sum(k)
for n=1:k {
y=0;
y=y+(1/(n+1)(n+2));
}
now call this function from command window by
sum(k) ----here k should be mentioned as integer
b)
x(1)=x(2)=1;
for n=1:18;
x(n+2)=x(n+1)+x(n)
X=[x(1) ; x(2) ; x(3) ; x(4) ; x(5) ; x(6) ; x(7) ; x(8) ; x(9) ; x(10) ; x(11) ;x(12);x(13);x(14);x(15);x(16);x(17);x(18);x(19);x(20)]
r= x(20)/x(19);
2) X=[1 10^-1 10^-2 10^-3 10^-4 10^-5 10^-6];
Y=(e.^X-ones(1,7))./X ------ .^ and ./ denote element by element operation
3) x=0:0.01:10;
y={40/(1+(x-4).^2)}+{5*sin(20.*x/pi)} ----- .^ and .* denote element by element
plot(x,y)