MATLAB Let f(x)=cosx. define a 1 =a, a 2 = f (a), a 3 = f(a2) = f (f(a)),..., a
ID: 2848632 • Letter: M
Question
MATLABLet f(x)=cosx. define a1 =a, a2 = f (a), a3 = f(a2) = f (f(a)),..., a n+1 =f(an ). plot the first 5 terms of this sequence (which, since it converges to a fixed point of f). Find the limit to within .00001. Gnerate the sequence using a for loop and test the five decimal place accuracy with an if statement (i.e., is | a n+1 - an | < .00001?) Alternatively, use a while loop plz shows code MATLAB
Let f(x)=cosx. define a1 =a, a2 = f (a), a3 = f(a2) = f (f(a)),..., a n+1 =f(an ). plot the first 5 terms of this sequence (which, since it converges to a fixed point of f). Find the limit to within .00001. Gnerate the sequence using a for loop and test the five decimal place accuracy with an if statement (i.e., is | a n+1 - an | < .00001?) Alternatively, use a while loop plz shows code
Explanation / Answer
part 1:
clc
a=1;
x=a;
for i=1:5
F(i)=cos(x);
x=F(i);
end
stem(F)
2)
clc
a=67;
x=a;
F(1,1)=cos(x);
F(1,2)=cos(F(1,1));
diff=abs(F(1,i)-F(1,i+1));
i=2;
while diff>=10^(-5)
i=i+1;
F(1,i)=cos(x);
x=F(i);
diff=abs(F(1,i)-F(1,i-1));
end
stem(F)
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.