Extracting a data vector from a looped ode45
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Frederik Bjerregaard
le 8 Déc 2021
Commenté : Star Strider
le 8 Déc 2021
Hi. I have a problem where i have to solve a system of equations numerically. I want to plot the maximum value for each result I get with the the a variable i am using (it is changing each iteration). However, when i try to plot it it seems it only uses the first result and variable.
clc; clear;close all;
% Defining parameters and initial conditions
f = 0.35;
r = [0.1:0.1:1.5];
zeta = 0.25;
Theta0 = [0.30, 0];
tspan = [0 20];
% Solver options
opts = odeset('RelTol',1e-6,'AbsTol',[1e-9 1e-9]);
% Solver
for i = 1:length(r)
[t,theta] = ode45(@(t,theta) odefcn(t,theta,f,r(i),zeta), tspan,Theta0);
Amp=max(theta(:,1));
plot(r,Amp);hold on;
end
I want to plot is so i have a line showing the change in Amp dependent on the change in r.
0 commentaires
Réponse acceptée
Star Strider
le 8 Déc 2021
I cannot run this because ‘odefcn’ is over the horizon.
I would do something like this —
% Defining parameters and initial conditions
f = 0.35;
r = [0.1:0.1:1.5];
zeta = 0.25;
Theta0 = [0.30, 0];
tspan = linspace(0, 20, 50);
% Solver options
opts = odeset('RelTol',1e-6,'AbsTol',[1e-9 1e-9]);
% Solver
for i = 1:length(r)
[t,theta] = ode45(@(t,theta) odefcn(t,theta,f,r(i),zeta), tspan,Theta0);
Amp(:,i)=max(theta(:,1));
end
figure
surf(t, r, Amp)
grid on
It may be necessary to reverse ‘t’ and ‘r’ in the surf call so that the dimensions will match appropriately.
.
3 commentaires
Star Strider
le 8 Déc 2021
As always, my pleasure!
(I remembered just now that it saves a point and not a vector, so that is appropriate.)
.
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Ordinary Differential Equations dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!