how to solve the below transcendental equation for the given data?

조회 수: 2 (최근 30일)
format compact
syms T t0
lambda=600; b=3;
theta=0.02;
c=5;
k=250;
h=1.75;
p=50;
M=.12;
Id=0.003;
TC=(k/T)+(c*lambda)+((lambda*(c*theta+h)*(exp(theta*t0)-theta*t0-1))/(T*(theta)^2))+((lambda*b*(T-t0)^2)/(2*T))+((lambda*p*M^2*Id)/(2*T));
dTCdt0=diff(TC,t0);
dTCdT=diff(TC,T);
[T,t0]=solve(dTCdt0,dTCdT)
Warning: Unable to solve symbolically. Returning a numeric solution using vpasolve.
T = 
0.8526169358775188513228900752894
t0 = 
0.5263315087626859744339029312836
t0=subs(t0);
digits(3)
t0=vpa(t0)
t0 = 
0.526
T=subs(T);
T=vpa(T)
T = 
0.853
TC=subs(TC);
digits(3)
TC=vpa(TC);
TC=round(TC)
TC = 
3587
%z=sqrt((2*k*(h+c*theta)*b)/(b+h+(c*theta)))*(sqrt(3800)-137.816)
  댓글 수: 3
Manikanta Aditya
Manikanta Aditya 2024년 4월 9일
The issue you're facing with the code not working consistently is likely due to the symbolic engine being reset or cleared between runs. This can happen if you're running the code in different sessions or if some other operation clears the symbolic engine's state.
To ensure consistent behavior, you could try encapsulating the entire code in a function and calling that function each time you want to execute it. This way, the symbolic engine's state is reset at the beginning of each function call.
Here's an example of how you could structure the code as a function:
function [T, t0, TC] = solve_transcendental_equation()
syms T t0
lambda = 600; b = 3;
theta = 0.02;
c = 5;
k = 250;
h = 1.75;
p = 50;
M = 0.12;
Id = 0.003;
TC = (k/T) + (c*lambda) + ((lambda*(c*theta+h)*(exp(theta*t0)-theta*t0-1))/(T*(theta)^2)) + ((lambda*b*(T-t0)^2)/(2*T)) + ((lambda*p*M^2*Id)/(2*T));
dTCdt0 = diff(TC, t0);
dTCdT = diff(TC, T);
[T_sol, t0_sol] = vpasolve(dTCdt0, dTCdT, [T, t0]);
T = double(T_sol);
t0 = double(t0_sol);
TC = subs(TC);
digits(3);
TC = vpa(TC);
TC = round(TC);
end
You can then call this function as many times as you need, and it should provide consistent results:
[T, t0, TC] = solve_transcendental_equation()
I hope this helps, if this helps, let me know I will post as answer, you can accept it to make it more helpful.
M.Rameswari Sudha
M.Rameswari Sudha 2024년 4월 9일
Thank you. Now, I understand the mistake. I got the answer.

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

채택된 답변

Manikanta Aditya
Manikanta Aditya 2024년 4월 9일
Hi,
The issue you're facing with the code not working consistently is likely due to the symbolic engine being reset or cleared between runs. This can happen if you're running the code in different sessions or if some other operation clears the symbolic engine's state.
To ensure consistent behavior, you could try encapsulating the entire code in a function and calling that function each time you want to execute it. This way, the symbolic engine's state is reset at the beginning of each function call.
Here's an example of how you could structure the code as a function:
function [T, t0, TC] = solve_transcendental_equation()
syms T t0
lambda = 600; b = 3;
theta = 0.02;
c = 5;
k = 250;
h = 1.75;
p = 50;
M = 0.12;
Id = 0.003;
TC = (k/T) + (c*lambda) + ((lambda*(c*theta+h)*(exp(theta*t0)-theta*t0-1))/(T*(theta)^2)) + ((lambda*b*(T-t0)^2)/(2*T)) + ((lambda*p*M^2*Id)/(2*T));
dTCdt0 = diff(TC, t0);
dTCdT = diff(TC, T);
[T_sol, t0_sol] = vpasolve(dTCdt0, dTCdT, [T, t0]);
T = double(T_sol);
t0 = double(t0_sol);
TC = subs(TC);
digits(3);
TC = vpa(TC);
TC = round(TC);
end
You can then call this function as many times as you need, and it should provide consistent results:
[T, t0, TC] = solve_transcendental_equation()
I hope this helps, if this helps, let me know I will post as answer, you can accept it to make it more helpful.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Functions에 대해 자세히 알아보기

제품


릴리스

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by