Clear Filters
Clear Filters

How to solve nonlinear equation?

5 views (last 30 days)
Semiha
Semiha on 11 May 2024
Edited: Torsten on 11 May 2024
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 Comment
Torsten
Torsten on 11 May 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.

Sign in to comment.

Answers (1)

Sam Chak
Sam Chak on 11 May 2024
Edited: Sam Chak on 11 May 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 Comments
Semiha
Semiha on 11 May 2024
I mean diff(x,t) == i(1 - x^3 - 0.5*x) and x(0)=0
Torsten
Torsten on 11 May 2024
Edited: Torsten on 11 May 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 = 

Sign in to comment.

Tags

Community Treasure Hunt

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

Start Hunting!