- 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.
ode45 Matlab system of differential equations
조회 수: 5 (최근 30일)
이전 댓글 표시
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! :)
댓글 수: 0
채택된 답변
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)]';
추가 답변 (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!