TIme Graph with Reoccurring Equations
Ältere Kommentare anzeigen
How would I graph a time graph of reoccurring equations in MATLAB? I started using MATLAB only recently and am not familiar with a lot of its functions. For example, if I wanted to graph the following equations 40 times (for 40 seconds for example) what code would I write?
x'=x.^2+x.*3+5;
With each passing second, x' updates itself. For example:
t=1:
x'=x.^2+x.*3+5;
t=2:
x''=x'.^2+x'.*3+5;
And so one for forty seconds (or for forty rounds of the above repetition.
Thank you.
Antworten (1)
the cyclist
am 4 Feb. 2012
This is almost certainly not what you intended, but it is basically what you asked for:
x0 = 0;
x = zeros(1,40);
x(1) = x0;
for t = 1:39
x(t+1) = x(t).^2 + x(t).*3 + 5;
end
plot(1:40,x,'.-')
This code creates a vector variable x and fills it in according to the rule you state. Given that x is squared at every repetition, you will see that MATLAB is only able to calculate the first 10 values of x. After that, x is so huge that it is assigned "Inf" (shorthand for infinity).
However, now that you see how to do this, maybe you will see how to correct this to do what you actually wanted.
Kategorien
Mehr zu Numerical Integration and Differential Equations finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!