symbolic code ends with an error
이전 댓글 표시
Tr = 0.5; M = 1; Kp = 0.1; K = 02; L = 0.5; D = 3; Rd = 0.5; Pr = 2; S1 = 0.01;
Nb = 02; Nt = 1; Le = 1; Kc = 1; m = 0.5; t1 = 0.5 ; s1 = 0.5; Ec = 0.5;
p1 = -2.1501; p2 = -1.0774; p3 = 1.8615; p4 = -1.5575;
t = sym('t'); x= sym('x');
f = zeros(1,1,'sym'); w = zeros(1,1,'sym'); g = zeros(1,1,'sym'); h = zeros(1,1,'sym');
fa = zeros(1,3,'sym'); wa = zeros(1,3,'sym'); ga = zeros(1,3,'sym'); ha = zeros(1,3,'sym');
f(1)= (p1*x^2)/2 + x; w(1) = p2*x - m*p1;g(1) = p3*x - t1 + 1;h(1)= p4*x - s1 + 1;
for i=1:3
fa(i) = subs(f(i),x,t); dfa = diff(fa(i),t,1); d2fa = diff(dfa,t,1);
wa(i) = subs(w(i),x,t); ga(i) = subs(g(i),x,t); ha(i) = subs(h(i),x,t);
dwa = diff(wa(i),t,1); dga = diff(ga(i),t,1); dha = diff(ha(i),t,1);
If1 = int(((M+(1/Kp))*dfa + dfa ^2 - dfa * d2fa - K*wa(i) -L*(ga(i)+D*ha(i))/(1+K)),t,0,t); If2 = int(If1,t,0,t);
f(i+1) = int(If2,t,0,x);
Iw1 = int((dfa*wa(i)- fa(i)*dwa + K*(2*wa(i)+ d2fa)/(1+(K/2))),t,0,t);
w(i+1) = int(Iw1,t,0,x);
Ig1 = - int((3*Rd *(Tr-1)*(1+(Tr-1)*ga(i))^2* dga^2 + Pr*(fa(i)*dga + Nb*dga*dha + Nt*dga^2 + S1*ga(i))+ ...
(1+K)*Ec*Pr* d2fa^2)./(1+Rd*(1+(Tr-1)*ga(i))^3),t,0,t);
g(i+1) = int(Ig1,t,0,x);
Ih1 = int( Pr*Le*Kc*ha(i) - fa(i)*dha + (Nt/Nb)*((3*Rd *(Tr-1)*(1+(Tr-1)*ga(i))^2* dga^2 + Pr*(fa(i)*dga + Nb*dga*dha + Nt*dga^2 + S1*ga(i))+(1+K)*Ec*Pr* d2fa^2)./(1+Rd*(1+(Tr-1)*ga(i))^3)),t,0,t);
h(i+1) = int(Ih1,t,0,x);
% disp(vpa(f(i+1)))
end
disp(vpa(g(2)))
f = f(1)+f(2)+f(3); w= w(1)+w(2)+w(3); g = g(1)+g(2)+g(3); h = h(1)+h(2)+h(3);
댓글 수: 11
Ameer Hamza
2020년 4월 22일
What are you trying to do in this code?
MINATI PATRA
2020년 4월 23일
Integration but in g nd h part one variable is divided that's why code gives NAN, some modification needed.
Ameer Hamza
2020년 4월 23일
Can you show the mathematical equations for this integration?
madhan ravi
2020년 4월 23일
dbstop if naninf
MINATI
2020년 4월 23일
MINATI
2020년 4월 23일
MINATI
2020년 4월 24일
Walter Roberson
2020년 4월 24일
Your code uses S, which is not defined. However, S1 is defined.
MINATI
2020년 4월 24일
Walter Roberson
2020년 4월 24일
On the first round, i=1, your integral for IG1 is undefined if t > (4000*2^(1/3))/3723 + 1000/1241 and is -inf when t is exactly that value. For reasons I am not clear on at the moment, MATLAB returns nan when it notices this.
Furthermore, MATLAB only returns this nan if you integrate the expression (which is in t) from a numeric constant less than (4000*2^(1/3))/3723 + 1000/1241 to t. If you create a new symbolic variable, B, and integrate the expression from 0 to B, then NaN is not returned: an unresolved integration is returned intead.
This suggests a work-around: integrate to a symbolic variable such as B. Since the resulting expression will have an unresolved integral, the result will be of the form int(expression,t,0,B), and since B is independent of t, then in theory the result will be in terms of B instead of in terms of t -- which will then be important in the next step because the next step assumes that t is present in the equation, so you would have to change that. Similar changes are needed for some of the other equations.
MINATI PATRA
2020년 4월 24일
Ok I will try and let u know the proceed
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Code Performance에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!