How to plot recursive definition in Matlab/Simulink?

where n is 1 to 10

A(n)=1.03*A(n-1)-700;

B(n)=(B(n-1)+50)*1.03;

(n-1) being the previous term of n

is it possible to plot those recursive definitions as two lines on the same graph in Matlab?

if so how?

ANSWER

Matlabsolutions.com provide latest MatLab Homework Help,MatLab Assignment Help for students, engineers and researchers in Multiple Branches like ECE, EEE, CSE, Mechanical, Civil with 100% output.Matlab Code for B.E, B.Tech,M.E,M.Tech, Ph.D. Scholars with 100% privacy guaranteed. Get MATLAB projects with source code for your learning and research.

Use a while loop and call functions for each. However, for this problem, consider using a for loop. It will be much more efficient since you can use the values immediately previous.

You will need to define A(1) and B(1). I’ll assume them to be 1 here.

nmx = 10;% Assuming A(1) and B(1) are 1, because they weren't otherwise defined.
A = ones(nmx,1);
B = ones(nmx,1);
for ix=2:nmx
A(ix) = 1.03*A(ix-1)-700;
B(ix) = 1.03*(B(ix-1)+50);
end
% Call the recursive function for each value of n
Ar = ones(nmx,1);
Br = ones(nmx,1);
for ix=1:nmx
[Ar(ix)] = A_recurse(ix);
[Br(ix)] = B_recurse(ix);
end
figure(1)
plot(1:nmx,A,'p');
hold on
plot(1:nmx,B,'o');
plot(1:nmx,Ar,'s');
plot(1:nmx,Br,'x');
hold off
legend('A','B','Ar','Br');
function A = A_recurse(n)
if n == 1
A = 1;
else

SEE COMPLETE ANSWER CLICK THE LINK

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Technical Source

Simple! That is me, a simple person. I am passionate about knowledge and reading. That’s why I have decided to write and share a bit of my life and thoughts to.