Help with Symbolic For Loop

So I have this code, and it works. But I can't figure out how to get it to store the answers of each of the 3 iterations. It only stores the last. I know it's something simple, maybe I've just been at it too long, but I can't seem to figure it out.
The Pnew = P(i) is in relation to P being 3 different load cases, i.e P = [0, 22.25, 44.5]
syms w(x) v(x)
Dw = diff(w);
Dv = diff(v);
for i = 1:1:3
Pnew = P(i)
% Delection in y direction
ode_v = diff(v,x,2) == -Izz/(E*den)*(Pnew*(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)
% Delection in Z direction
ode_w = diff(w,x,2) == Iyz/(E*den)*(Pnew*(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

2 个评论

For the for loop you could just use
syms y(x)
for i = 1:3
z(i) = y^i;
end
Yep, that did it, I just had to soak in what you were telling me. THANKS!!!

请先登录,再进行评论。

回答(0 个)

类别

帮助中心File Exchange 中查找有关 Loops and Conditional Statements 的更多信息

产品

版本

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by