Help with Symbolic For Loop

1 view (last 30 days)
Terry Poole
Terry Poole on 31 Mar 2021
Edited: Terry Poole on 31 Mar 2021
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 Comments
Jan de Jong
Jan de Jong on 31 Mar 2021
For the for loop you could just use
syms y(x)
for i = 1:3
z(i) = y^i;
end
Terry Poole
Terry Poole on 31 Mar 2021
Edited: Terry Poole on 31 Mar 2021
Yep, that did it, I just had to soak in what you were telling me. THANKS!!!

Sign in to comment.

Answers (0)

Categories

Find more on Symbolic Math Toolbox in Help Center and File Exchange

Products


Release

R2019b

Community Treasure Hunt

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

Start Hunting!