Mass Matrix SWITCH Problem in Matlab
2 views (last 30 days)
Show older comments
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!
Answers (4)
Walter Roberson
on 7 Apr 2016
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 Comments
Torsten
on 8 Apr 2016
Maybe
dy = double( subs(Fss_bend, {sym('u'), sym('v'), sym('y')}, {u, v, y'}) );
?
Best wishes
Torsten.
Marius
on 21 Apr 2016
13 Comments
Walter Roberson
on 23 Apr 2016
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(:))
See Also
Categories
Find more on Ordinary Differential Equations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!