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()
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));
[T_sol, t0_sol] = vpasolve(dTCdt0, dTCdT, [T, t0]);
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.