TIme Graph with Reoccurring Equations
Afficher commentaires plus anciens
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.
Réponses (1)
the cyclist
le 4 Fév 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.
Catégories
En savoir plus sur Numerical Integration and Differential Equations dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!