Problem using ode45

15 visualizzazioni (ultimi 30 giorni)
Paulina Urban
Paulina Urban il 28 Mag 2018
Risposto: Star Strider il 28 Mag 2018
I have two files: 1 file has this code: function xprime = lorenz(t,x); alfa = 0.017; beta = 0.067; tau_e = 0.017; tau_l = 0.0001; tau_j =0.00000001; tau_k =0.00000001; c = 0.000001; p = 0.000001; d = 0.000001; A = 475; xprime = zeros(6,1); t0=20.0; xprime(1) =A*( c1*x(2) + x(3)*tau_k -(tau_l*x(1) - tau_j*x(1))); and so on
second file has this code clear all; x0 = [0 0 0.8 0.2 0 0]; tspan = [0 500]; [t,x]=ode45(@lorenz,tspan,x0); save('A475.mat','x','t')
Because I want to calculate a lot of ode but each with different A - how can i put A value in my second file ?
I was trying like clear all; x0 = [0 0 0.8 0.2 0 0]; tspan = [0 500]; A=475; [t,x]=ode45(@lorenz,tspan,x0,[],A); save('A475.mat','x','t')
but it gives me an error. Undefined function or variable 'A'.
Error in lorenz (line 107) xprime(1) =A*( c1*x(2) + x(3)*tau_k -(tau_l*x(1) - tau_j*x(1)));
Error in odearguments (line 90) f0 = feval(ode,t0,y0,args{:}); % ODE15I sets args{1} to yp0.
Error in ode45 (line 115) odearguments(FcnHandlesUsed, solver_name, ode, tspan, y0, options, varargin);
Error in run (line 5) [t,x]=ode45(@lorenz,tspan,x0,A);
I'm using matlab version R2017a

Risposte (1)

Star Strider
Star Strider il 28 Mag 2018
Include ‘A’ in the argument list to ‘lorenz’, then pass it as an extra parameter in your ode45 call.
Function:
function xprime = lorenz(t,x,A);
...
end
Calling script:
...
A = 475;
[t,x] = ode45(@(t,x)lorenz(t,x,A) ,tspan,x0);
See the documentation on Passing Extra Parameters (link) for a detailed description.

Categorie

Scopri di più su Programming in Help Center e File Exchange

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by