How to use ode45 with initial conditions defined in script?
4 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Hello, I am using ode45 to solve a differential equation. Here is the function file:
.m
function TempP=primary(Tp,y)
hp=13.64;
Tw=25;
mp=0.007;
Cp=1005;
TempP=-2*hp*(Tp-Tw)/(mp*Cp);
Now I have code in script: demo.m
clear all
yrange=[0:0.02:0.9];
Tp=40;
[Tp,y]=ode45(@primary,yrange,Tp);
figure(1)
plot(Tp,y)
ylabel('Tp (deg C)')
xlabel ('Y (m)')
If you can notice, the variables hp,Tw,mp,Cp are defined in primary.m but what I want is, to define in them in demo.m This will help me to control the initial conditions when I have such more function .m files. Is that possible?
0 Kommentare
Antworten (2)
Star Strider
am 17 Sep. 2016
You can easily pass your parameters to ‘primary’ from ‘demo’:
function TempP=primary(Tp,y,hp,Tw,mp,Cp)
TempP=-2*hp*(Tp-Tw)/(mp*Cp);
end
hp=13.64;
Tw=25;
mp=0.007;
Cp=1005;
yrange=[0:0.02:0.9];
Tp0=40;
[Tp,y]=ode45(@(Tp,y) primary(Tp,y,hp,Tw,mp,Cp),yrange,Tp0);
figure(1)
plot(Tp,y)
ylabel('Tp (deg C)')
xlabel ('Y (m)')
0 Kommentare
Siehe auch
Kategorien
Mehr zu Ordinary Differential Equations finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!