MATLAB Answers

0

Duffing Oscillator issue. "Keep getting Unable to perform assignment because the left and right sides have a different number of elements."

Eva Carrillo さんによって質問されました 2019 年 11 月 19 日 2:08
最新アクティビティ James Tursa
さんによって 回答されました 2019 年 11 月 19 日 2:15
The Duffing Oscillator is as follows:
To do this, we have to use the Euler-Cromer method to solve, which follows the following syntax:
and
My code is as follows:
clc;
T=10;
N=1000;
deltat=T/N;
omega=1.2;
alpha=1.5;
beta=0;
delta=0;
gamma=0;
x=[N 1];
y=[N 1];
t=[N 1];
x(1)=0;
y(1)=0;
x2=[N 1];
y2=[N 1];
x2(1)=x(1);
y2(1)=y(1);
t(1)=0;
for n=1:N
x(n+1)=x(n)+y(n)*deltat;
y(n+1)=y(n)+deltat*(gamma*cos(omega*t)-delta*x(n)-alpha*x(n+1)-beta*x(n+1).^3);
x2(n+1)=x2(n)+y2(n)*deltat;
y2(n+1)=y2(n)-k*y2(n)*deltat-(omega^2)*cos(x2(n+1))*deltat;
t(n+1)=t(n)+deltat;
end
figure(1)
plot(t,x);
hold on;
plot(x,y);
I just keep getting "Unable to perform assignment because the left and right sides have a
different number of elements." For the line which I went ahead and bolded
I've never used the Euler-Cromer method before, so maybe I'm doing something wrong, but honestly am not sure. Help would be much appreciated!

  0 件のコメント

サインイン to comment.

1 件の回答

回答者: James Tursa
2019 年 11 月 19 日 2:15

t is a vector, so your cos(omega*t) is a vector. You need to use cos(omega*t(n)) there.

  0 件のコメント

サインイン to comment.



Translated by