Simulation of Equation Set Equal to Zero

5 ビュー (過去 30 日間)
Spencer Ferris
Spencer Ferris 2021 年 12 月 10 日
編集済み: Torsten 2021 年 12 月 11 日
I'm trying to run simulations on the following equation:
Second-dervative(x) + gamma * x^2 * derivative(x) - alpha * derivative(x) + omega^2 * x = 0
Gamma, alpha, and omega are constants that I plug in and vary to see changes in the function.
From my understanding, the second derivative of a variable to the power of 1 (i.e. X^1) is always 0, and the first derivative is always 1.
If I plug in 1 for Gamma, alpha and Omega, I end up with this equation.
0 + 1.*(x.^2) * 1 - 1.*1 + 1^2 .* x
My question is, how do I simulate this equation, equal to zero? Here's the code I am working with.
% Set paramaters.
xo = 0;
x = [xo];
t = [0];
x0 = [-1, 0, 1 ];
% Simulate
[t,x] = ode23(@fx, [0 10], x0);
plot (t,x,"LineWidth",2)
xlabel("t")
ylabel("x")
xlim = [0 10];
ylim = [0 10];
function xdot = fx(t,x)
xdot = 0 + 1.*(x.^2) * 1 - 1.*1 + 1^2 .* x;
end
Is this the right way to do it? I feel like I'm missing something.
  2 件のコメント
Torsten
Torsten 2021 年 12 月 10 日
編集済み: Torsten 2021 年 12 月 10 日
x usually is a function of the independent variable t.
So derivative(x) means dx(t)/dt, not dx/dx = 1.
Similarly Second-derivative(x) means d^2x(t)/dt^2, not d^2x/dx^2 = d1/dx = 0.
Spencer Ferris
Spencer Ferris 2021 年 12 月 10 日
Ah I knew I was missing something! So how would I take the derivative of x with respect to t in matlab?

サインインしてコメントする。

採用された回答

Sam Chak
Sam Chak 2021 年 12 月 10 日
Looks like the Van der Pol oscillator.
clear all; clc
tspan = 0:0.001:10;
y0 = [1; 0];
[t, y] = ode45(@(t,y) [y(2); y(2) - ((y(1)).^2).*y(2) - y(1)], tspan, y0);
plot(t, y)
plot(y(:, 1), y(:, 2))
  2 件のコメント
Spencer Ferris
Spencer Ferris 2021 年 12 月 10 日
It is! So part of what I have to do is vary gamma, alpha and omega, what values do I change here to vary them? Thank you!
Torsten
Torsten 2021 年 12 月 11 日
編集済み: Torsten 2021 年 12 月 11 日
tspan = 0:0.01:10;
y0 = [1; 0];
alpha = 1;
gamma = 1;
omega = 1;
[t, y] = ode45(@(t,y) [y(2); -gamma*y(1)^2*y(2)+alpha*y(2)-omega^2*y(1)], tspan, y0);
plot(t, y)
plot(y(:, 1), y(:, 2))

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeGamma Functions についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by