Help indexing symbolic ODE in for loop

조회 수: 2 (최근 30일)
Terry Poole
Terry Poole 2021년 3월 31일
댓글: Terry Poole 2021년 3월 31일
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.

채택된 답변

Walter Roberson
Walter Roberson 2021년 3월 31일
wSol{i} = vpa(simplify(wSol),3)
  댓글 수: 2
Terry Poole
Terry Poole 2021년 3월 31일
Error using sym/subsasgn (line 951)
Invalid indexing assignment.
Error in LabSix (line 84)
wSol{i} = vpa(simplify(wSol),3)
Terry Poole
Terry Poole 2021년 3월 31일
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!

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Conversion Between Symbolic and Numeric에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by