How to use ode45 with initial conditions defined in script?
4 ビュー (過去 30 日間)
古いコメントを表示
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 件のコメント
回答 (2 件)
Star Strider
2016 年 9 月 17 日
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 件のコメント
参考
カテゴリ
Help Center および File Exchange で Ordinary Differential Equations についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!