ode45 Matlab system of differential equations

조회 수: 5 (최근 30일)
Leah Powell
Leah Powell 2015년 4월 8일
댓글: Leah Powell 2015년 4월 8일
Hi,
I'm new to Matlab and I have been trying to solve/simulate values of my system of ordinary differential equations. Even when I copy and paste examples from the net Matlab tells me that my function is undefined. For example:
function ypsir =ypsir(t,y) a = .01; b = .1; ypsir(1) =-a*y(1)*y(2); ypsir(2) = a*y(1)*y(2)-b*y(2); ypsir(3) = b*y(2); ypsir = [ypsir(1) ypsir(2) ypsir(3)]';
Matlab will respond with
??? Input argument "y" is undefined.
Error in ==> Untitled at 4 ypsir(1) =-a*y(1)*y(2);
Can someone please explain what this means and how to fix it.
Thanks! :)

채택된 답변

Mischa Kim
Mischa Kim 2015년 4월 8일
편집: Mischa Kim 2015년 4월 8일
Leah, use something like
function ODE_test()
[t,Y] = ode45(@ypsir_ODE,[0 10],[1 1 1]);
plot(t,Y)
function ypsir = ypsir_ODE(t,y)
a = .01; b = .1;
ypsir(1) =-a*y(1)*y(2);
ypsir(2) = a*y(1)*y(2)-b*y(2);
ypsir(3) = b*y(2);
ypsir = [ypsir(1) ypsir(2) ypsir(3)]';
  • Re-name the ODE function name since you use it also as the return value; I used ypsir_ODE.
  • Save the functions in one file, called ODE_test.m.

추가 답변 (0개)

카테고리

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