New Matlab user. My equations say I do not have enough inputs. How do I correct this?
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Alex F
am 14 Sep. 2018
Bearbeitet: Walter Roberson
am 15 Sep. 2018
tspan = linspace(0,15,201);
y0=[0 15];
[t, y] = ode15s(f,tspan,y0);
function dydt=f(t,y)
dydt(1)=1.57-.00145 *y(1)*y(2);
dydt(2)=7.30-.53*y(1)-.00145*y(1)*y(2);
plot(t,y);
end
0 Kommentare
Akzeptierte Antwort
madhan ravi
am 14 Sep. 2018
Bearbeitet: madhan ravi
am 14 Sep. 2018
tspan = linspace(0,15,201);
y0=[0 ;15];
[t, y] = ode15s(@f1,tspan,y0)
plot(t,y(:,1),'-o')
hold on
plot(t,y(:,2),'-ob')
function dydt=f1(t,y)
dydt(1)=1.57-.00145 *y(1)*y(2);
dydt(2)=7.30-.53*y(1)-.00145*y(1)*y(2);
dydt=[dydt(1);dydt(2)] %added this line to make sure it’s a column vector.
end
Note:See the function file attached.
Use
[t, y] = ode15s(@f1,tspan,y0)
Instead of
[t, y] = ode15s(f1,tspan,y0)
6 Kommentare
madhan ravi
am 14 Sep. 2018
Bearbeitet: madhan ravi
am 14 Sep. 2018
@f indicates that the function is called with its inputs. I don’t know why you’re getting empty graph but I didn’t have any problem getting the graph.
Stephen23
am 15 Sep. 2018
"Is there a reason why the @f is used?"
Because ode15s requires the first input to be a function handle:
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Ordinary Differential Equations finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!