What's the wrong ?
7 views (last 30 days)
Show older comments

the MATLAB program Matlab:edit, Then,the following lines between the percent sign (%) copied to m.file, save %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% function dx=myfun(t,x)
dx(1)-x(3)+x(2)-x(4)*x(2)+2*x(5)*x(2)+x(2)*x(2)+x(5)+e+f+g=0; dx(2)-x(1)+x(3)-x(4)*x(2)+x(2)*x(2)+x(5)*x(5)+x(5)*x(2)+e*f+g=0; dx(3)-x(2)+x(1)-x(5)*x(1)+x(4)*x(3)-x(3)-x(4)-e*g-f=0; x(4)*x(5)+x(2)*x(3)+e*f+e*g-x(6)=0; dx(4)-x(5)*a-x(3)*x(1)-x(3)-e*f*g*x(6)=0; dx(5)-x(4)*a-x(2)*x(1)+e*f*x(1)+x(2)*x(2)*x(5)+x(2)*x(5)*x(5)+e*f+f*g=0;
a=a1+a2; e=e1+e2; f=f1+f2; g=g1+g2;
a1=1; a2=1; e1=9; e2=7; f1=56; f2=98; g1=76; g2=665;
dx=dx(:); %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Matlab: clear all clc syms a e f g a1 a2 e1 e2 f1 f2 g1 g2 x0=[1,1,1,1,1,1]; t0=0:0.1:2; [t,x]=solver('myfun',[0,10],x0); %ode45会自动调整步长 plot(t,x) legend('x(1)','x(2)','x(3)','x(4)','x(5)','x(6)')
1 Comment
Jan
on 11 Mar 2015
Edited: Jan
on 11 Mar 2015
Please use a meaningful tag. If you explain, why you think, that there is something wrong, we do not have to guess this fundamental detail. Please avoid non-english comments, format your code properly in the forum and explain the problem with details. Thanks.
clear all removes all debugger breakpoints. But the debugger is the freidn of programmers. So start with deleting this cruel command, such that you can use the debugger to examine the code.
Answers (1)
Jan
on 11 Mar 2015
dx(1)-x(3)+x(2)-x(4)*x(2)+2*x(5)*x(2)+x(2)*x(2)+x(5)+e+f+g = 0;
This is a formula, but to assignment operation in Matlab. You should get an error message for this code. If so, please post it and look for examples for using ODE45.
syms a e f g a1 a2 e1 e2 f1 f2 g1 g2
You do not use these symbolic variables inside the function to be integrated. Defining them as symbolic outside this function is not meaningful.
0 Comments
See Also
Categories
Find more on Symbolic Math Toolbox in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!