教授再问一下 也是数值分析的<BR>引用了MATLAB的函数<STRONG>ode23<BR></STRONG>这个列向量为yprime。同样,y1和y2合并写成列向量y。所得函数M文件是:<BR>
<P 0cm 0cm 0pt; TEXT-INDENT: 24pt"><FONT face="Times New Roman">function yprime=vdpol(t , y);</FONT></P>
<P 0cm 0cm 0pt; TEXT-INDENT: 24pt"><FONT face="Times New Roman">% VDPOL(t , y) returns derivatives of the Van der Pol equation:</FONT></P>
<P 0cm 0cm 0pt; TEXT-INDENT: 24pt"><FONT face="Times New Roman">% </FONT></P>
<P 0cm 0cm 0pt; TEXT-INDENT: 24pt"><FONT face="Times New Roman">% x </FONT>‘‘<FONT face="Times New Roman">-mu *(1-x ^2)*x </FONT>‘<FONT face="Times New Roman">+x=0 (</FONT>‘<FONT face="Times New Roman"> = d/dx , </FONT>‘‘<FONT face="Times New Roman"> = d^2/dx^2)</FONT></P>
<P 0cm 0cm 0pt; TEXT-INDENT: 24pt"><FONT face="Times New Roman">% </FONT></P>
<P 0cm 0cm 0pt; TEXT-INDENT: 24pt"><FONT face="Times New Roman">% let y(1)=x and y(2)=x</FONT>‘</P>
<P 0cm 0cm 0pt; TEXT-INDENT: 24pt"><FONT face="Times New Roman">% </FONT></P>
<P 0cm 0cm 0pt; TEXT-INDENT: 24pt"><FONT face="Times New Roman">% then y(1)</FONT> ‘<FONT face="Times New Roman"> = y(2)</FONT></P>
<P 0cm 0cm 0pt; TEXT-INDENT: 24pt"><FONT face="Times New Roman">% y(2)</FONT> ‘<FONT face="Times New Roman"> = MU*(1-y(1)^2)*y(2)-y(1)</FONT></P>
<P 0cm 0cm 0pt; TEXT-INDENT: 24pt"><p><FONT face="Times New Roman"> </FONT></p></P>
<P 0cm 0cm 0pt; TEXT-INDENT: 24pt"><FONT face="Times New Roman">global MU % choose 0<MU<10 in Command workspace</FONT></P>
<P 0cm 0cm 0pt; TEXT-INDENT: 24pt"><p><FONT face="Times New Roman"> </FONT></p></P>
<P 0cm 0cm 0pt; TEXT-INDENT: 24pt"><FONT face="Times New Roman">yprime=[y(2) MU*(1-y(1)^2)*y(2)-y(1)]; % output must be a column</FONT></P>
<P 0cm 0cm 0pt; TEXT-INDENT: 24pt"><p><FONT face="Times New Roman"> </FONT></p></P>
<P 0cm 0cm 0pt; TEXT-INDENT: 24pt">计算结果如下:</P>
<P 0cm 0cm 0pt; TEXT-INDENT: 24pt"><p><FONT face="Times New Roman"> </FONT></p></P>
<P 0cm 0cm 0pt; TEXT-INDENT: 24pt"><FONT face="Times New Roman">>>global MU % define MU as a global variable in the Command Workspace</FONT></P>
<P 0cm 0cm 0pt; TEXT-INDENT: 24pt"><FONT face="Times New Roman">>>MU=2; % set global parameter to desired value</FONT></P>
<P 0cm 0cm 0pt; TEXT-INDENT: 24pt"><FONT face="Times New Roman">>>[t , y]=ode23(‘</FONT> <FONT face="Times New Roman">vdpol ’</FONT><FONT face="Times New Roman"> , 0 , 30 , [1 ; 0]); % to=0 , tf=30 , yo=[1 ; 0]</FONT></P>
<P 0cm 0cm 0pt; TEXT-INDENT: 24pt"><FONT face="Times New Roman">>>y1=y( : , 1); % first column is y(1) versus time points in t</FONT></P>
<P 0cm 0cm 0pt; TEXT-INDENT: 24pt"><FONT face="Times New Roman">>>y2=y( : , 2); % second column is y(2)</FONT></P>
<P 0cm 0cm 0pt; TEXT-INDENT: 24pt"><FONT face="Times New Roman">>>plot(t , y1 , t , y2 , </FONT>‘ <FONT face="Times New Roman">-- </FONT>‘<FONT face="Times New Roman">)</FONT></P>
<P 0cm 0cm 0pt; TEXT-INDENT: 24pt"><FONT face="Times New Roman">>>xlabel(</FONT>‘<FONT face="Times New Roman"> Time , Second </FONT>‘<FONT face="Times New Roman">) , ylabel(</FONT>‘<FONT face="Times New Roman"> Y(1) and Y(2) </FONT>‘<FONT face="Times New Roman">)</FONT></P>
<P 0cm 0cm 0pt; TEXT-INDENT: 24pt"><FONT face="Times New Roman">>>title(</FONT>‘<FONT face="Times New Roman"> Van der Pol Solution for mu=2 </FONT>‘<FONT face="Times New Roman">)<BR>前面是对的 按例应该可以出图的 (后面有问题)<BR></P>
<P 0cm 0cm 0pt; TEXT-INDENT: 24pt"><FONT face="Times New Roman">[t , y]=ode23(</FONT>‘ <FONT face="Times New Roman">vdpol </FONT>‘<FONT face="Times New Roman"> , 0 , 30 , [1 ; 0]); % to=0 , tf=30 , yo=[1 ; 0]<BR>我替换成了<BR> <FONT face="Times New Roman">[t , y]=ode23(‘</FONT><FONT face="Times New Roman">vdpol</FONT><FONT face="Times New Roman"> ’, [0 , 30] , [1 , 0]); <BR>但是后面还是有错 <BR>能帮我看下指导下吗?</FONT></FONT></P></FONT> |