Help indexing symbolic ODE in for loop

Ok so my code works,
P = [0; 22.25; 44.5];
syms w(x) v(x)
Dw = diff(w);
Dv = diff(v);
for i = 1:3
% Deflection in y direction
ode_v = diff(v,x,2) == -Izz/(E*den)*(P(i)*(L-x));
cond1_v = v(0) == 0;
cond2_v = Dv(0) == 0;
conds_v = [cond1_v cond2_v];
vSol(x) = dsolve(ode_v,conds_v);
vSol = vpa(simplify(vSol),3)
% Deflection in Z direction
ode_w = diff(w,x,2) == Iyz/(E*den)*(P(i)*(L-x));
cond1_w = w(0) == 0;
cond2_w = Dw(0) == 0;
conds_w = [cond1_w cond2_w];
wSol(x) = dsolve(ode_w,conds_w);
wSol = vpa(simplify(wSol),3)
end
And my output is:
vSol(x) =
0.0
wSol(x) =
0.0
vSol(x) =
1.41e+13*x^2*(x - 3.0)
wSol(x) =
3.14e+13*x^2*(x - 3.0)
vSol(x) =
2.82e+13*x^2*(x - 3.0)
wSol(x) =
6.29e+13*x^2*(x - 3.0)
>>
Which is correct for all 3 load cases,
My issue is, I'm not sure how to call each case, I can't say vSol(1), because it'll assume x=1 and solve the differential equation. So how would I "index" for lack of a better word each case to generate a plot of (v,w) vs. P? I assume since its a syms function that it's not storing these values as an array, honestly it doesn't seem like it's storing them at all.
Any help on how to call vSol(x)(1), vSol(x)(2) and so on would be greatly appreciated.

 Respuesta aceptada

Walter Roberson
Walter Roberson el 31 de Mzo. de 2021
wSol{i} = vpa(simplify(wSol),3)

2 comentarios

Terry Poole
Terry Poole el 31 de Mzo. de 2021
Error using sym/subsasgn (line 951)
Invalid indexing assignment.
Error in LabSix (line 84)
wSol{i} = vpa(simplify(wSol),3)
ode_w = diff(w,x,2) == Iyz/(E*den)*(P(i)*(L-x));
cond1_w = w(0) == 0;
cond2_w = Dw(0) == 0;
conds_w = [cond1_w cond2_w];
wSol(x) = dsolve(ode_w,conds_w);
wSol = vpa(simplify(wSol),3)
ws{i} = wSol
That did it! Thanks!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Variables en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 31 de Mzo. de 2021

Comentada:

el 31 de Mzo. de 2021

Community Treasure Hunt

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

Start Hunting!

Translated by