Function Loop with ODE45

Hi, I have a system of ODEs being solved by ode45 at a specified temperature. I want to solve the system for a range of temperatures then plot the result at each temperature. How do I make the function m. file and the call m. file change temperature at the same time using a loop? Ie, I want to solve the system at a temperature and hold the data, then change to another temperature and hold the data.

回答 (1 件)

Mischa Kim
Mischa Kim 2014 年 10 月 29 日

0 投票

Sarah, check out the function below. This should get you started:
function phase()
IC = 5*(rand(50,2)-0.5);
hold on
for ii = 1:length(IC(:,1))
[~,X] = ode45(@EOM,[-5 5],IC(ii,:));
u = X(:,1);
w = X(:,2);
plot(u,w,'r')
end
xlabel('u')
ylabel('w')
grid
x = -4:0.5:4;
y = -4:0.5:4;
[xg,yg] = meshgrid(x,y);
dxg = yg.*xg.^2 - xg;
dyg = ones(length(x)) - yg - yg.*xg.^2;
scale = 5;
quiver(xg,yg,dxg,dyg,scale)
end
function dX = EOM(t, y)
dX = zeros(2,1);
u = y(1);
w = y(2);
A = 1;
B = 1;
dX = [(w*u^2 - B*u);...
(A - w - w*u^2)];
end

カテゴリ

ヘルプ センター および File ExchangeProgramming についてさらに検索

タグ

質問済み:

2014 年 10 月 28 日

回答済み:

2014 年 10 月 29 日

Community Treasure Hunt

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

Start Hunting!

Translated by