[英]solve system of differential equation in matlab
I am trying to solve a system of differential equations in Matlab. 我正在尝试在Matlab中解决微分方程组。
dn/du=(-2*u*n-K*(n*u-(1+g)))/(1+u^2+K*u*(u-(1+g)/n))
dxi/du=(1-u^2)/(1+u^2+K*u*(u-(1+g)/n))
df/du=(2*u+K*u^2*(u-(1+g)/n))/(1+u^2+K*u*(u-(1+g)/n))
K and gamma are constants. K和伽玛是常数。 I have the initial conditions like so:
我有这样的初始条件:
n(0)=1, xi(0)=0, f(0)=0
First i tried to use 'dsolve'. 首先,我尝试使用'dsolve'。
g=0.1;
K=3;
syms n(u) u
n(u)=dsolve(diff(n,u)== (-2*u*n-K*(n*u-(1+g)))/(1+u^2+K*u*(u-(1+g)/n)),n(0)==1)
syms x(u) u n
x(u)= dsolve(diff(x,u)== (1-u^2)/(1+u^2+K*u*(u-(1+g)/n)),x(0)==0)
syms f(u) u n
f(u)=dsolve(diff(f,u)== (2*u+K*u^2*(u-(1+g)/n))/(1+u^2+K*u*(u-(1+g)/n)),f(0)==0)
from this i get that there is not explicit solution for the first equation and returned an [empty sym] as shown below. 由此我得到第一个方程式没有明确的解决方案,并返回了一个[empty sym],如下所示。
Warning: Explicit solution could not be found.
警告:找不到明确的解决方案。
In dsolve (line 201)
处于溶解状态(201行)
In Untitled (line 37)
在无标题(第37行)中
n(u) = [ empty sym ]
n(u) = [空符号]
x(u) = (1089*atan(33/(1600*n^2 - 1089)^(1/2) - (80*n*u)/(1600*n^2 - 1089)^(1/2)))/(160*n*(1600*n^2 - 1089)^(1/2)) - (35937*log(40*n*u^2 - 33*u + 10*n))/(2*(- 256000*n^3 + 174240*n)) - u/4 + (33*log(10*n)*(1600*n^2 - 1089)^(1/2) - 2178*atan(33/(1600*n^2 - 1089)^(1/2)) + 8000*n^2*atan(33/(1600*n^2 - 1089)^(1/2)))/(320*n*(1600*n^2 - 1089)^(1/2)) - (25*n*atan(33/(1600*n^2 - 1089)^(1/2) - (80*n*u)/(1600*n^2 - 1089)^(1/2)))/(1600*n^2 - 1089)^(1/2) + (26400*n^2*log(40*n*u^2 - 33*u + 10*n))/(- 256000*n^3 + 174240*n)
x(u) =(1089 * atan(33 /(1600 * n ^ 2-1089)^(1/2)-(80 * n * u)/(1600 * n ^ 2-1089)^(1/2 )))/(160 * n *(1600 * n ^ 2-1089)^(1/2))-(35937 * log(40 * n * u ^ 2-33 * u + 10 * n))/( 2 *(-256000 * n ^ 3 + 174240 * n))-u / 4 +(33 * log(10 * n)*(1600 * n ^ 2-1089)^(1/2)-2178 * atan( 33 /(1600 * n ^ 2-1089)^(1/2))+ 8000 * n ^ 2 * atan(33 /(1600 * n ^ 2-1089)^(1/2)))/(320 * n *(1600 * n ^ 2-1089)^(1/2))-(25 * n * atan(33 /(1600 * n ^ 2-1089)^(1/2)-(80 * n * u )/(1600 * n ^ 2-1089)^(1/2)))/(1600 * n ^ 2-1089)^(1/2)+(26400 * n ^ 2 * log(40 * n * u ^ 2-33 * u + 10 * n))/(-256000 * n ^ 3 + 174240 * n)
f(u) = (3*u^2)/8 - (33*u)/(160*n) - (log(40*n*u^2 - 33*u + 10*n)*(3200000*n^4 - 3920400*n^2 + 1185921))/(2*(- 10240000*n^4 + 6969600*n^2)) + (log(10*n)*(3200000*n^4 - 3920400*n^2 + 1185921))/(2*(- 10240000*n^4 + 6969600*n^2)) + (33*atan((1089*(2800*n^2 - 1089))/((1600*n^2 - 1089)^(1/2)*(92400*n^2 - 35937)))*(2800*n^2 - 1089))/(6400*n^2*(1600*n^2 - 1089)^(1/2)) - (33*atan((1089*(2800*n^2 - 1089))/((1600*n^2 - 1089)^(1/2)*(92400*n^2 - 35937)) - (2640*n u (2800*n^2 - 1089))/((1600*n^2 - 1089)^(1/2)*(92400*n^2 - 35937)))*(2800*n^2 - 1089))/(6400*n^2*(1600*n^2 - 1089)^(1/2))
f(u) =(3 * u ^ 2)/ 8-(33 * u)/(160 * n)-(log(40 * n * u ^ 2-33 * u + 10 * n)*(3200000 * n ^ 4-3920400 * n ^ 2 + 1185921))/(2 *(-10240000 * n ^ 4 + 6969600 * n ^ 2))+(log(10 * n)*(3200000 * n ^ 4-3920400 * n ^ 2 + 1185921))/(2 *(-10240000 * n ^ 4 + 6969600 * n ^ 2))+(33 * atan((1089 *(2800 * n ^ 2-1089))/(((1600 * n ^ 2-1089)^(1/2)*(92400 * n ^ 2-35937))*(2800 * n ^ 2-1089))/(6400 * n ^ 2 *(1600 * n ^ 2- 1089)^(1/2))-(33 * atan((1089 *(2800 * n ^ 2-1089))/((1600 * n ^ 2-1089)^(1/2)*(92400 * n ^ 2-35937))-(2640 * n u (2800 * n ^ 2-1089))/(((1600 * n ^ 2-1089)^(1/2)*(92400 * n ^ 2-35937)) )*(2800 * n ^ 2-1089))/(6400 * n ^ 2 *(1600 * n ^ 2-1089)^(1/2))
Then i tried to use 'ode45'. 然后,我尝试使用“ ode45”。
u=0:0.1:1;
K=3;
g=0.1;
dndu=@(u,n) (-2*u*n-K*(n*u-(1+g)))/(1+u^2+K*u*(u-(1+g)/n));
[u,n]=ode45(dndu, u, 1) % initial n=1
dxidu=@(u,xi) (1-u^2)/(1+u^2+K*u*(u-(1+g)/n));
[u,xi]=ode45(dxidu, u, 0); %initial xi=0
dfdu=@(u,f) (2*u+K*u^2*(u-(1+g)/n))/(1+u^2+K*u*(u-(1+g)/n));
[u,f]=ode45(dfdu, u, 0) %initial f=0
K and g are constants and u gets values for 0 to 1. When i run this the first equation is solved and got an answer for u and n but i get an error for the second equation that matrix dimension must agree as shown below. K和g是常数,并且u获得0到1的值。当我运行此方程时,第一个方程式被求解并得到u和n的答案,但是第二个方程式却出现了一个误差,矩阵尺寸必须一致,如下所示。
u = 0 0.1000 0.2000 0.3000 0.4000 0.5000 0.6000 0.7000 0.8000 0.9000 1.0000
u = 0 0.1000 0.2000 0.3000 0.4000 0.5000 0.6000 0.7000 0.8000 0.9000 1.0000
n = 1.0000 1.3409 1.6243 1.7746 1.7945 1.7263 1.6119 1.4800 1.3470 1.2208 1.1048
n = 1.0000 1.3409 1.6243 1.7746 1.7945 1.7263 1.6119 1.4800 1.3470 1.2208 1.1048
Error using /
使用/时出错
Matrix dimensions must agree.矩阵尺寸必须一致。
Error in @(u,xi)(1-u^2)/(1+u^2+K u (u-(1+g)/n))
@(u,xi)(1-u ^ 2)/(1 + u ^ 2 + K u (u-(1 + g)/ n))中的错误
Error in odearguments (line 87)
排列错误(第87行)
f0 = feval(ode,t0,y0,args{:});f0 = feval(ode,t0,y0,args {:}); % ODE15I sets args{1} to yp0.
%ODE15I将args {1}设置为yp0。
Error in ode45 (line 113)
ode45中的错误(第113行)
[neq, tspan, ntspan, next, t0, tfinal, tdir, y0, f0, odeArgs, odeFcn, ...[neq,tspan,ntspan,next,t0,tfinal,tdir,y0,f0,odeArgs,odeFcn,...
Error in ode45method (line 24)
ode45方法错误(第24行)
[u,xi]=ode45(dxidu, u, 0);[u,xi] = ode45(dxidu,u,0); %initial xi=0
%initial xi = 0
Can anyone help me how to approach this type of problem? 谁能帮助我解决这类问题? Thanks in advance!
提前致谢!
You have a system of coupled differential equations, you need to solve it as a coupled system. 您有一个耦合的微分方程组,需要将其作为一个耦合系统进行求解。 One ODE function for a vector valued function with 3 components.
一个ODE函数用于具有3个分量的矢量值函数。
u1=0:0.01:1;
K=3;
g=0.1;
dydu=@(u,y)[(-2*u*y(1)-K*(y(1)*u-(1+g)))/(1+u^2+K*u*(u-(1+g)/y(1)))
(1-u^2)/(1+u^2+K*u*(u-(1+g)/y(1)))
(2*u+K*u^2*(u-(1+g)/y(1)))/(1+u^2+K*u*(u-(1+g)/y(1)))];
[U,Y]=ode45(dydu,u1,[1 0 0]);
n=Y(:,1);
xi=Y(:,2);
f=Y(:,3);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.