How to solve nonlinear equation?

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 commentaire

Torsten
Torsten le 11 Mai 2024
If it helps: You can get t as an analytical function of x, but I think it's not possible to solve for x.

Connectez-vous pour commenter.

Réponses (1)

Sam Chak
Sam Chak le 11 Mai 2024
Modifié(e) : Sam Chak le 11 Mai 2024
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 commentaires

Or, you can try finding an implicit solution:
syms x(t);
ode = diff(x,t) == 1 - x^3 - 0.5*x;
cond = x(0) == 1;
xSol(t) = dsolve(ode, cond, 'Implicit', true)
xSol(t) = 
Semiha
Semiha le 11 Mai 2024
I have already derive a numerical solution by using ode45 in matlab and also in mathematica. I need to derive an analytical solution. Yes, maybe there is no an explict analytical solution. But at least I tried to find plot(lxl,t), if it is possible.
Thank you for your kind response.
Torsten
Torsten le 11 Mai 2024
Modifié(e) : Torsten le 11 Mai 2024
syms x(t) u
ode = diff(x,t) == 1 - x^3 - 0.5*x;
cond = x(0) == 1;
xSol = dsolve(ode, cond, 'Implicit', true);
xSol = subs(xSol,x,u);
T = 0:0.1:10;
X = arrayfun(@(T)vpasolve(subs(xSol,t,T),u),T)
X = 
plot(T,X)
Warning: Imaginary parts of complex X and/or Y arguments ignored.
grid on
Semiha
Semiha le 11 Mai 2024
Thank you so much for your response.
A question come to my mind, what If I turn to equation diff(x,t) == i(1 - x^3 - 0.5*x); where i is imaginary it gives error.
This solution is valid only for the real functions?
Semiha
Semiha le 11 Mai 2024
I mean diff(x,t) == i(1 - x^3 - 0.5*x) and x(0)=0
Torsten
Torsten le 11 Mai 2024
Modifié(e) : Torsten le 11 Mai 2024
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 = 

Connectez-vous pour commenter.

Tags

Question posée :

le 11 Mai 2024

Modifié(e) :

le 11 Mai 2024

Community Treasure Hunt

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

Start Hunting!

Translated by