plot - MATLAB two for loops for a range and a recurrence equation -
i have been given recurrence equation: x(n) = ax(n-1)/1+bx(n-1). having trouble plotting solution matlab 2014b, returns figure plots multiple curves range o:10 on single graph. have far in terms of making range in form of y:
function questions1 () n = 100; %xn in form of n x = zeros (n,1); x(1) = 0; = 2; b = 1; y = 0:10; %this range 0:10 plot curves n = 2:n; x(n) = a*x(n-1)/1+b*x(n-1); %this recurrence equation end end hold on; plot(x); hold off;
notice that
x(0)=0 x(1)=a*x(0)/1+b*x(0)=a*0+b*0=0 x(2)=a*x(1)+b*x(1)=a*0+b*0=0 .. ∀n, x(n)=0
so recursive equation quite bad.. , you're replacing x(n) on each y-iteration, here fix:
function question1() n = 100; %xn in form of n x = zeros(n,1); x(1) = 0; = 2; b = 1; hold on; y = 0:10; %this range 0:10 plot curves n = 2:n; x(n) = a*x(n-1)/1+b*x(n-1); %this recurrence equation end plot(x); end hold off;
Comments
Post a Comment