필터 지우기
필터 지우기

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