필터 지우기
필터 지우기

Mass Matrix SWITCH Problem in Matlab

조회 수: 1 (최근 30일)
Marius
Marius 2016년 4월 7일
댓글: Marius 2016년 4월 23일
I'm having a problem with my ODE in Matlab. The code to start the ODE solver is the following:
refine = 4;
options = odeset('Refine', refine,...
'RelTol', 1e-9,'absTol',1e-9*ones(1,length(y_sym)),'Mass',Mss_bend,'MassSingular','no','MstateDependence','strong')
[t_bend_i,y_bend_i] = ode45(@(t,y) ...
bending_DGL(t,y,time_r,dt,ug,vg,Mss_bend,Fss_bend,Sys,flag),time_r_i,IC_bend_i,options);
And the corresponding function file containing the ODE is:
function dy = bending_DGL(t,y,time_r,dt,ug,vg,Mss_bend,Fss_bend,Sys,flag)
r = Sys.r;
roh = Sys.roh;
A = Sys.A;
I = Sys.I;
ne = Sys.ne;
nnode = Sys.nnode;
ndof = Sys.ndof;
Le = Sys.Le;
E = Sys.E;
g = Sys.g;
EI = E*I;
EA = E*A;
%Interpolate Earthquake Excitation
i = floor(t/dt) + 1;
if i < length(time_r)
u = ug(i) + (t-time_r(i))/(time_r(i+1)-time_r(i))*(ug(i+1)-ug(i));
v = vg(i) + (t-time_r(i))/(time_r(i+1)-time_r(i))*(vg(i+1)-vg(i));
else
u = 0;
v = 0;
end
%Load State Space Representation of Problem
switch flag
case ''
dy = Fss_bend;
case 'mass'
dy = Mss_bend;
end
Now I'm trying to solve the ODE where Mss_bend is the mass matrix which is symbolic, because it is statedependent so Mss_bend(y,t) and Fss_bend(y,t) is the right side of the Equation which is state dependent too. So now I wan't to solve the Problem Mss_bend(y,t)*dy = Fss_bend where dy is the derivative of the vector y with respect to time.
When I start the calculation it gives me the
Error: Switch expression must be a scalar or string constant.
Error in bending_DGL (line 31)
switch flag
Error in @(t,y)bending_DGL(t,y,time_r,dt,ug,vg,Mss_bend,Fss_bend,Sys,flag)
Error in odearguments (line 87)
What did i do wrong? Is there a problem because the matrices are symbolic?
Matlab tell's me in the function file that y is unused:
function dy = bending_DGL(t, y,time_r,dt,ug,vg,Mss_bend,Fss_bend,Sys,flag
How do I solve this Problem. y is as symbolics in the Mss_bend and Fss_bend where y(1), y(2) etc is declared as symbols.
Thank you for your answers!
  댓글 수: 1
Marius
Marius 2016년 4월 9일
I found the solution! I had to load the symbolic y vector
y_sym = [y(1), y(2), y(3) ...]
into my function file, end then make
Fss_bend = subs(Fss_bend,y_sym,y)
Fss_bend = subs(Fss_bend,{sym('u'), sym('v')}, {u, v}
dy = double(Fss_bend);

댓글을 달려면 로그인하십시오.

답변 (4개)

Walter Roberson
Walter Roberson 2016년 4월 7일
We would need to see how you initialized your flag variable to figure out why you are getting the error for switch.
You will need to change your code anyhow. Assuming that your Fss_bend and Mss_bend are expressions rather than functions:
%Load State Space Representation of Problem
switch flag
case ''
dy = double( subs(Fss_bend, {sym('t', sym('y')}, {t, y}) );
case 'mass'
dy = double( subs(Mss_bend, {sym('t', sym('y')}, {t, y}) );
end
However, it seems likely that your Mss_bend and Fss_bend also use some of the variables that you compute, such as u and v. We need to know whether Mss_bend and Fss_bend are functions or expressions, and if they are functions we need to know the order they expect their arguments in. If they are expressions then we need to know which symbolic variables need to be substituted.
  댓글 수: 7
Marius
Marius 2016년 4월 8일
Hmm I tested it and you are right. If I just run my dy function it returns a 256x1 vector whith 16 different results each in 16 following rows. Like:
dy = 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,...
so it repeats each result 16 times?
Torsten
Torsten 2016년 4월 8일
Maybe
dy = double( subs(Fss_bend, {sym('u'), sym('v'), sym('y')}, {u, v, y'}) );
?
Best wishes
Torsten.

댓글을 달려면 로그인하십시오.


Marius
Marius 2016년 4월 8일
Thank you for your answer!
1)We would need to see how you initialized your flag variable to figure out why you are getting the error for switch.
What do you mean with this? All I have done with the flag is already in the code. What did I miss? Sorry I have never worked with flags and the Mass representation of ODE's before.
2)You will need to change your code anyhow. Assuming that your Fss_bend and Mss_bend are expressions rather than functions.
Fss_bend is a 16x1 symbolic vector which contains 'u','v', and 'y(1)' - 'y(16)' as symbolic variables. Mss_bend is a strongly nonlinear 16x16 symbolic matrix which contains 'y(1)' - 'y(16)'. as symbolic variables.
What do I need to change?

Marius
Marius 2016년 4월 21일
Is there another possibility to do this? Is it true that now it is substituting the variables in each step of the ODE15s solver? This takes very long. Isn't there a way that doesn't use subs?
  댓글 수: 13
Marius
Marius 2016년 4월 23일
Now i got the next error:
Error using odearguments (line 90)
@(T,Y)ROCKING_DGL(T,Y,TIME_R,DT,UG,VG,FSSFUN,SYS) must return a column vector.
Error in ode15s (line 148)
[neq, tspan, ntspan, next, t0, tfinal, tdir, y0, f0, odeArgs, odeFcn, ...
Error in Processing (line 270)
[t_up,y_up,te,ye,ie] = ode15s(@(t,y) ...
Walter Roberson
Walter Roberson 2016년 4월 23일
What is your FssFun reshape()'ing to? It should be reshaping to a column vector.
If you are using matlabFunction(something) to generate FssFun then use matlabFunction(something(:))

댓글을 달려면 로그인하십시오.


Marius
Marius 2016년 4월 23일
Now it gives me the error:
Error using odearguments (line 92)
@(T,Y)ROCKING_DGL(T,Y,TIME_R,DT,UG,VG,FSSFUN,SYS) returns a vector of length 576, but the length of initial conditions
vector is 24. The vector returned by @(T,Y)ROCKING_DGL(T,Y,TIME_R,DT,UG,VG,FSSFUN,SYS) and the initial conditions
vector must have the same number of elements.
Error in ode15s (line 148)
[neq, tspan, ntspan, next, t0, tfinal, tdir, y0, f0, odeArgs, odeFcn, ...
Error in Processing (line 270)
[t_up,y_up,te,ye,ie] = ode15s(@(t,y) ...
  댓글 수: 1
Marius
Marius 2016년 4월 23일
I had to change it to:
FssFun = matlabFunction(Fss(:,1), 'vars', {'t', y, 'u', 'v'})

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Ordinary Differential Equations에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by