Trouble with newmark method code. its not working and i don't know why. I want to get u,v and a from these equations
Afficher commentaires plus anciens
Could someone please help. I am trying to write a code for the new mark method but its not working and i can't figure out why.
%Time
ti=0;
dt=0.02;
tf=5.98;
t=ti:dt:tf;
nt=length(t);
%force
for t=0:0.02:6
p0=[0;0;0;132482]*t
p1=p0+[0;0;0;2649.64]
end
%Constants
alpha=0;
beta=0;
a1=alpha+(1/(0.5*dt));
b=beta+(0.5*dt);
c=0.5*dt;
d=(1-0.5)*dt;
e=1/0.5;
f=beta-((1-0.5)*dt);
g=1/(0.5*dt);
h=(1-0.5)/0.5;
%Initial conditions
u(:,1)=zeros;
v(:,1)=zeros;
a(:,1)=zeros;
MM=[1044,0,0,0;0,733.46,0,0;0,0,457.8,0;0,0,0,44.67];
KM=[9900000000,-9893000000,0,0;0,10000000000,-439000000,0;0,0,1370000000,-932200000;0,0,-932200000,932200000];
%time step
for it=1:nt-1
for t=1:nt-1
p0=[0;0;0;132482]*t;
p1=p0+[0;0;0;2649.64];
end
u(:,it+1)=((c*p1)+(d*p0)+(a1*MM*u(:,it))+(e*MM*v(:,it))+(f*KM*u(:,it)))./((a*MM)+(b*KM))
v(:,it+1)=g*(u(:,it+1)-u(:,it))-(h*v(:,it))
a(:,it+1)=g*(v(:,it+1)-v(:,it))-(h*a(:,it))
end
1 commentaire
Geoff Hayes
le 7 Mar 2015
Laura - if I run the above code, I observe the error
Error using +
Matrix dimensions must agree.
Error in *** (line 37)
u(:,it+1)=((c*p1)+(d*p0)+(a1*MM*u(:,it))+(e*MM*v(:,it))+(f*KM*u(:,it)))./((a*MM)+(b*KM))
This is because you are adding a 4x1 matrices p1 and p0 to a 4x4 matrix MM. What are you expecting to occur at this line? What is the algorithm (reference) that you are using to develop your code?
Réponses (0)
Catégories
En savoir plus sur Geoscience dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!