How to solve nonlinear equation?

5 次查看(过去 30 天)
Semiha
Semiha 2024-5-11
编辑: Torsten 2024-5-11
Hello,
I wrote the following code to derive an analytical solution to nonlinear equation but it gives an error. Could you please help me to fix it? Or any suggestion to solve in an analytical way. Thanks
syms x(t);
ode = diff(x,t) == -1*(1-abs(x)^2*x-(1-0.5)*x);
cond = x(0) == 1;
xSol(t) = dsolve(ode,cond);
Warning: Unable to find symbolic solution.
t = 0:1:100;
xSols = xSol(t);
plot(t,xSols)
Error using plot
Invalid data argument.
  1 个评论
Torsten
Torsten 2024-5-11
If it helps: You can get t as an analytical function of x, but I think it's not possible to solve for x.

请先登录,再进行评论。

回答(1 个)

Sam Chak
Sam Chak 2024-5-11
编辑:Sam Chak 2024-5-11
I'm afraid that the nonlinear differential equation may not have an analytical solution. In such cases, you can utilize the 'ode45' solver to obtain a numerical solution.
ode = @(t, x) 1*(1 - abs(x)^2*x - (1 - 0.5)*x);
tspan = [0 10]; % simulation time
x0 = 1; % initial value
options = odeset('RelTol', 1e-4, 'AbsTol', 1e-6);
[t, x] = ode45(ode, tspan, x0, options);
plot(t, x), grid on, xlabel('t'), ylabel('x(t)')
  6 个评论
Semiha
Semiha 2024-5-11
I mean diff(x,t) == i(1 - x^3 - 0.5*x) and x(0)=0
Torsten
Torsten 2024-5-11
编辑:Torsten 2024-5-11
I don't know why for the symbolic solution, not for all t-values solutions for x are returned.
ode = @(t, x) 1i*(1 - x^3 - 0.5*x);
tspan = [0 10]; % simulation time
x0 = 0; % initial value
[t, x] = ode45(ode, tspan, x0);
figure(1)
plot(t, real(x)), grid on, xlabel('t'), ylabel('real(x(t))')
figure(2)
plot(t, imag(x)), grid on, xlabel('t'), ylabel('imag(x(t))')
syms x(t) u
ode = diff(x,t) == 1i*(1 - x^3 - 0.5*x);
cond = x(0) == 0;
xSol = dsolve(ode, cond, 'Implicit', true);
xSol = subs(xSol,x,u);
vpasolve(subs(xSol,t,1),u)
ans = 

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Equation Solving 的更多信息

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by