- You are basically working with two functions: the main function ( myODE ) and the function defining the differential equations. Make sure to complete each function with an end-command.
- The parameters ( a,b,c ) need to be passed to the second function. I am using a vector called params.
Solving nonlinear differential system from matlab website giving error
조회 수: 2 (최근 30일)
이전 댓글 표시
Hi community members! I have been trying to solve a nonlinear differential system for work and to learn, copied in the exact code from a tutorial found at: http://www.mathworks.com/help/matlab/ref/ode45.html (Example 1) Whenever I try to run it, my Matlab gives me an error at line 3:

Any help on this would be deeply appreciated. I am basically looking to solve the system numerically since analytically seems impossible. If somebody has a better way of doing this, that would be much appreciated. Thanks in advance!
댓글 수: 0
답변 (1개)
Mischa Kim
2014년 6월 26일
편집: Mischa Kim
2014년 6월 26일
Devansh, use
function myODE()
options = odeset('RelTol',1e-4,'AbsTol',[1e-4 1e-4 1e-5]);
a = 1; b = 2; c = 3;
params = [a; b; c];
[T,Y] = ode45(@rigid,[0 12],[0 1 1],options,params);
plot(T,Y(:,1),'-',T,Y(:,2),'-.',T,Y(:,3),'.')
end
function dy = rigid(t,y,params)
a = params(1);
b = params(1);
c = params(1);
dy = zeros(3,1); % a column vector
dy(1) = a*y(2) * y(3);
dy(2) = -b*y(1) * y(3);
dy(3) = -c*0.51 * y(1) * y(2);
end
and save the entire file as myODE.m.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Matrix Computations에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!