编程知识 cdmana.com

On solving differential equations with MATLAB

img


Find the answer to the question , The code you write always reports errors . I hope someone can give me some advice , Thank you very much




Refer to the answer 1:

Hello !
Numerical solution :

% y(1) Corresponding y;y(2) Corresponding zf = @(x,y)  [sin(x)+y(2); 1+x-y(1)];[x,y] = ode45(f, [0,10], [2;7]);plot(x,y); legend('y','z')

img

Analytic solution :

syms y(x) z(x) xeq = [diff(y,1)-sin(x)==z, diff(z,1)+y==1+x];conds = [y(0)==2, z(0)==7];s = dsolve(eq,conds);z = matlabFunction(s.z);y = matlabFunction(s.y);fplot(y, [0,10], 'r--'); hold onfplot(z, [0,10], 'b-');legend('y','z')

img

Helpful, hope to adopt




Refer to the answer 2:



Refer to the answer 3:

analysis

syms y z x;[y z]=dsolve('Dy-z=sin(x)','Dz+y=1+x','y(0)=2','z(0)=7','x');vpa(y)vpa(z)

The number

% y  yes y(1)  z yes y(2)f = @(x,y)[sin(x)+y(2);1-x-y(1)];[x,y]=ode45(f,[0,200],[2;7]);plot(x,y(:,1));hold on;plot(x,y(:,2));grid on;

img




Refer to the answer 4:

版权声明
本文为[CSDN Q & A]所创,转载请带上原文链接,感谢
https://cdmana.com/2021/10/20211021230021166m.html

Scroll to Top