Filter löschen
Filter löschen

ODE45 2DOF Unable to perform assignment because the left and right sides have a different number of elements.

4 Ansichten (letzte 30 Tage)
Hi good people,
I'm trying to solve this:
clc
clear all
close all
x0=0;
xdot0=0;
IC=[x0 xdot0];
t=0:0.1:10;
[t,x]=ode45( @MDOF1, t, IC );
when the MDOF1 function looks like:
function dxdt=MDOF1(t,x)
m=[2 2];
M=diag(m);
C=[4 -2;-2 4];
K=[8 -4;-4 8];
F=10*sin(10*t);
dxdt(1)=x(2);
dxdt(2)=inv(M)*F-(inv(M)*C)*x(2)-(inv(M)*K)*x(1)
dxdt=[dxdt(1);dxdt(2)];
end
and i get this error:
Unable to perform assignment because the left and right sides have a different number of elements.
Error in MDOF1 (line 8)
dxdt(2)=inv(M)*F-(inv(M)*C)*x(2)-(inv(M)*K)*x(1)
Error in odearguments (line 90)
f0 = feval(ode,t0,y0,args{:}); % ODE15I sets args{1} to yp0.
Error in ode45 (line 115)
odearguments(FcnHandlesUsed, solver_name, ode, tspan, y0, options, varargin);
Error in mdof1_ode (line 8)
[t,x]=ode45( @MDOF1, t, IC );
Could anyone advise me what I'm doing wrong?
  10 Kommentare
Piotr Haciuk
Piotr Haciuk am 26 Jan. 2019
David,
I made a slight modification to the function script:
function dxdt=MDOF1(t,x)
m=[10000 10000];
M=diag(m);
C=[800 -400;-400 800];
K=[800 -400;-400 800];
F1=100*sin(10*t);
F=[F1; F1];
dxdt = zeros(4,1);
dxdt(1:2)=x(3:4);
dxdt(3:4)=inv(M)*F-(inv(M)*C)*x(3:4)-(inv(M)*K)*x(1:2);
end
The equation I'm aiming to solve looks like:
[M]x''+[C]x'+[K]x=F
Dividing through by [M] and leaving x'' on the LHS gives:
x''=F/[M]-[C]x'-[K]x
I assume the function script is written correctly now
Next question is how to extract x(1),x(2) and x'(1),x'(2) and plot them as a total response?
What i have so far is this:
clc
clear all
close all
x10=0;
x1dot0=0;
x20=0;
x2dot0=0;
IC=[x10 x20 x1dot0 x2dot0];
t=0:0.01:500;
[t,x]=ode45( @MDOF1, t, IC );
x1 = x(:,1);
x2 = x(:,2);
v1 = x(:,3);%x'(1)
v2 = x(:,4);%x'(2)
xfinal=x1+v1;
vfinal=x2+v2;
Piotr Haciuk
Piotr Haciuk am 26 Jan. 2019
Guess I got it!
function dxdt=MDOF1(t,x)
m=[100000 100000];
M=diag(m);
C=[80000 -40000;-40000 80000];
K=[80000 -40000;-40000 80000];
F1=100*sin(10*t);
F2=10*sin(5*t);
F=[F1; F2];
dxdt = zeros(4,1);
dxdt(1:2)=x(3:4);
dxdt(3:4)=inv(M)*F-(inv(M)*C)*x(3:4)-(inv(M)*K)*x(1:2);
end
Main:
clc
clear all
close all
x10=1;
x1dot0=0.1;
x20=0.5;
x2dot0=0.05;
IC=[x10 x20 x1dot0 x2dot0];
t=0:0.01:50;
[t,x]=ode45( @MDOF1, t, IC );
plot(t,x(:,1))
xlabel('t'); ylabel('x');
hold on
plot(t,x(:,2))
hold on
plot(t,x(:,3))
hold on
plot(t,x(:,4))
legend('x1','x2','v1','v2')
hold off
And the result attached

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

David Goodmanson
David Goodmanson am 27 Jan. 2019
HI Piotr,
I decided to post one last observation as an answer, which you may respond to as you wish.
Since you have a couple of driving sine functions, the system must eventually settle down to an equilibrium state of constant amplitudes for x's and v's. My first reaction on seeing your plot was that there must be something wrong, because the solution was decaying away. However, it turns out that your initial conditions are quite large compared to equilibrium. If you run the time out to 100 seconds and zoom in, you can see equilibrium ampliudes around 10^-4, considerably smaller than your initial conditions. Or if you use IC = [0 0 0 0] you can see the system settle down quite a bit more quickly. Overall it appears that things are looking good.
  2 Kommentare
Piotr Haciuk
Piotr Haciuk am 27 Jan. 2019
I'd like to thank you for your contribution towards the outcome, without your help I'd struggle for the next few weeks. so thank you very much! now i have to built on that my main target. Respond to the masses movements on the surface of a bridge modelled using Finite element method.
David Goodmanson
David Goodmanson am 28 Jan. 2019
Bearbeitet: David Goodmanson am 28 Jan. 2019
Your'e welcome, I was glad to contribute. At this point expanding to more elements is simple, at least in principle, and hopefully you will get good results.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Programming finden Sie in Help Center und File Exchange

Tags

Produkte


Version

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by