stem-plot difference of equations

Here is the question
Find numerically and stem-plot the solutions of the difference equations [1<=k<=10]
a. y(k+1) - 3*k*y(k) = 0
b. y(y+1) - k*y(k) = 1
assume that y(1)=1
not sure if i am looking at this properly but here is what i was thinking. a and b do not have the same y values after 1 since in order to get 0 for the first one y(2) needs to be 3 while for equation b y(2) needs to be 2. So solve them differently and then plot? i am not sure which would be my x and y for stem plot as well. This looks simple but its confusing me not sure if am over thinking.
Thank you for your time

3 Comments

Your question is not clear. Do you want to solve two different equations or one system of two equations?
that is the main question sorry if it was not but i am not sure if its suppose to be answered separate or together
Are you sure that (b) should have y(y+1) on the left side, and not y(k+1) ??

Sign in to comment.

 Accepted Answer

Once you have the set of values x1 with y1, and x2 with y2, you can use interp1() to interpolate each set of data over a common set of times; then you can stem().
For example,
y1_interp = interp1(x1, y1, 1:10)
y2_interp = interp1(x2, y2, 1:10)
plot(1:10, y1_interp, 1:10, y2_interp)

4 Comments

Write your equations as
ya(k+1) - 3*k*ya(k) = 0
yb(k+1) - k*yb(k) = 1
Then solve both equations against k = 1 to 10, producing ya and yb. Then
stem(1:10, ya)
and
stem(1:10, yb)
The question does not ask you to plot them on the same figure and does not ask you to calculate any relationship between the two. (The question as shown also does not ask you to do anything with the stem plots other than to create them.)
Tony
Tony on 30 Dec 2013
Edited: Tony on 30 Dec 2013
thank you sorry for the double post i was not sure if comments would get pushed up.
Last thing is just a coding error that i am not sure how to fix. for ya i get
ya =
1.0e+011 *
0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0001 0.0026 0.0714 2.1428
if i were to type ya(1) for example i would get 1 ya(2) 3 and so on but i get this when checking the values in the array. I do not get this error for yb
ya= zeros(size(11));
yb= zeros(size(11));
ya(1)=1;
yb(1)=1;
for k = 1:10;
ya(k+1) = (3)*(k)*ya(k)
yb(k+1) = k*yb(k)+ 1
end
figure, stem(1:11,ya), hold on,stem(1:11,yb)
Tony
Tony on 31 Dec 2013
Edited: Tony on 31 Dec 2013
edit actually doesn't seem to display properly with stem
second edit - its good thank you happy holiday
At the command line give the command
format long g

Sign in to comment.

More Answers (1)

Tony, try this iterative method :
y1=zeros(10,1);
y2=zeros(10,1);
y1(1)=1;y2(1)=1; % initial conditions
for t=1:9
y1(t+1)=3*t*y1(t);
y2(t+1)=1+t*y2(t);
end
k=1:10;
figure, stem(k,y1), hold on,stem(k,y2,'r')

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!