How to use ODE45 with multiple initial conditions?

조회 수: 9 (최근 30일)
Blake
Blake 2015년 10월 5일
답변: Torsten 2015년 10월 6일
I"ve created a function that uses ode45 to draw solution curves for an equation in the x1x2-plane this phase portrait is supposed to be on the same plot as a direction field as well as plot the initial conditions. My coding for the phase portrait is as follows:
function [ output_args ] = phasePortrait(A,tmin,tmax,x1init,x2init)
%UNTITLED3 Summary of this function goes here
% Detailed explanation goes here
directionField(A)
hold on
f= @(t,y) [A(1,1).*y(1) + A(1,2).*y(2);A(2,1).*y(1) + A(2,2).*y(2)];
[t,y]=ode45(f,[tmin, tmax],[x1init, x2init]);
hold on
plot(y(:,1),y(:,2))
hold on
plot(x1init, x2init)
axis(-2.5,2.5,-2.5,2.5)
title('Phase Portrait')
xlabel('x1(t)')
ylabel('x2(t)')
end
*When I call the function I get an error saying that I have vectors of different lengths for the intial conditions and the results. How do I fix this or am I imputing something wrong?*
tmin=0
tmax=20
A=[-1 2;-2 -1]
x1init=[-2.5 1.5 2.5 -2.5]
x2init=[0 -2.5 0 2]
figure
phasePortrait(A,tmin, tmax, x1init, x2init)

답변 (1개)

Torsten
Torsten 2015년 10월 6일
Call ode45 four times in a loop, first for [x1init(1) x2init(1)] as initial condition, then for [x1init(2) x2init(2)] as initial condition and so on.
Best wishes
Torsten.

카테고리

Help CenterFile Exchange에서 Ordinary Differential Equations에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by