Extracting a data vector from a looped ode45
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
Frederik Bjerregaard
il 8 Dic 2021
Commentato: Star Strider
il 8 Dic 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 Commenti
Risposta accettata
Star Strider
il 8 Dic 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 Commenti
Star Strider
il 8 Dic 2021
As always, my pleasure!
(I remembered just now that it saves a point and not a vector, so that is appropriate.)
.
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Ordinary Differential Equations in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!