How can i plot a term of a function divided by the previous term of said function?

Lets say i have a file wrote which gives me the outputs of a given series. (e.g. 7x^2+x)
How do i plot x(n+1)/x(n)?
Im looking for a way to do that for all the values of say n=1 to n=25.

Answers (1)

yrat=y(2:end)./y(1:end-1);
plot(x(2:end,yrat)
the choice of which x to use for the abscissa is somewhat arbitrary, maybe you'll want to use xrat instead of an absolute x

6 Comments

I have changed the x to xrat, however the following error message arrives; Any idea how to solve this?
Subscript indices must either be real positive integers or logicals.
Error in ROB (line 8) plot(xrat(2:end,yrat))
x = 1:26;
series = 7*x.^2 + x;
plot(x(1:end-1), series(1:end-1).\series(2:end))
How about if i had a matrix 'R' which is 5 by 4. How do i plot element 1 over element 2,element 3 over element 2, element 4 over element 3, and so on?
plot(x(2:end,yrat)
Clearly there's a typo -- the unbalanced paren's shouldn't be hard to spot.
plot(x(2:end),yrat)
Just add the ':' for the row index to refer to all elements of each column.
R(2:end,:)./R(1:end-1,:)
Need to read up on "Getting Started" documentation on the colon operator and general Matlab syntax for addressing arrays and work thru the examples some.
I dont want to call all elements in a given row or column, i want to plot the frst element/2nd element, 2nd element/3rd element. etc
1 by 1
Me no follow...what are the "first element/2nd element, 2nd element/3rd element" specifically referring to?
And, specifically, what is the 1x1 reference to? You mean you want a scatter plot instead of a line plot, or are you looking at animation of adding a point at a time or what?

Sign in to comment.

Categories

Find more on 2-D and 3-D Plots in Help Center and File Exchange

Asked:

on 12 Feb 2014

Edited:

dpb
on 12 Feb 2014

Community Treasure Hunt

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

Start Hunting!