Just need the code for (a) I haven\'t had any luck. Thanks in advance! Consider
ID: 2844655 • Letter: J
Question
Just need the code for (a) I haven't had any luck. Thanks in advance!
Explanation / Answer
%copy the text into matlab and click run
%generates three graphs, A18 - A21 data files in .xls fomat (Microsoft excel)
clear all;
clc;
%Initialisation
N=40;
x=zeros(N,3);
x(1,1)=0.5;
x(1,2)=0.5;
x(1,3)=0.5;
rho(1)=0.5;
rho(2)=2.6;
rho(3)=3.8;
fg=1;
for i=1:N
x(i+1,1)=rho(1)*x(i,1)*(1-x(i,1));
x(i+1,2)=rho(2)*x(i,2)*(1-x(i,2));
x(i+1,3)=rho(3)*x(i,3)*(1-x(i,3));
if(x(i+1)<10^-6 && fg)
n=i;
K(1,1)=n;
K(2,1)=x(i+1,1);
fg=0;
display(n);
end
end
% I have writeen output to Excel files, for easy usage
%(a) part
xlswrite('A18.xls',x(1:N,1));
xlswrite('A19.xls',x(1:N,1));
xlswrite('A20.xls',x(1:N,1));
%(b) part
xlswrite('A21.xls',K);
range=1:N;
% Uncomment if you do not want plotting
figure(1)
plot(range,x(1:N,1));
title('For rho=0.5')
xlabel('No. of iterations')
ylabel('x')
figure(2)
plot(range,x(1:N,2));
title('For rho=2.6')
xlabel('No. of iterations')
ylabel('x')
figure(3)
plot(range,x(1:N,3));
title('For rho=3.8')
xlabel('No. of iterations')
ylabel('x')
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.