Function Loop with ODE45
Ältere Kommentare anzeigen
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.
Antworten (1)
Mischa Kim
am 29 Okt. 2014
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
Kategorien
Mehr zu Programming finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!