I am attempting to code a function with a differential (temperature with respect to time) and i am unsure how to do so

1 次查看(过去 30 天)
The equation i am attempting to code is in the following image. Tj (temp) and t (time) are matrix values how do i code this to get a single collumb matrix for TG?

回答(3 个)

Walter Roberson
Walter Roberson 2023-12-7
You can pass T and to gradient() to get estimated derivative of . Multiply by τ, add Tj, result is . Transpose to get a column vector if you need to.

Sulaymon Eshkabilov
If you are attempting to solve it numerically, you can do so using ode45, ode23, ode113, etc., built in functions. You'd need to have an initial condition and tau value, e.g.:
Tj0 = pi; % Initial Condition
tau = 2; % Value of tau
timespan = [0, 13]
timespan = 1×2
0 13
[time, TG] =ode45(@(t,Tj)-Tj/tau, timespan, Tj0);
plot(time, TG, 'ro--', 'markerfacecolor', 'c')
grid on
xlabel('t, [s]')
ylabel('T_G')
% or simply to get a plot
figure
ode45(@(t,Tj)-Tj/tau, timespan, Tj0)

Sam Chak
Sam Chak 2023-12-7
You probably won't post a question here if you're searching on Google for "how to solve an ordinary differential equation (ODE) in MATLAB". There are two approaches: (1) Symbolic, and (2) Numerical. First things first are to recognize the type of ODE that you are attempting to solve. The ODE solvers cannot directly solve the ODE in the form posted in your image.
Therefore, the ODE has to be rearranged into this form:
so that the solver can perform the integration to obtain T_{J}(t)
is typically known as the non-zero external input to the ODE system, and it affects the behavior of . In fact, T_{G} ccan be a non-zero constant, a time-varying function , or a state-dependant function . This type of ODE is known as the Non-homogeneous Differential Equation.
For the numerical approach, you can code the ODE like this using the function method, and then apply (or 'call' in CS terminology) the ode45() function to solve the ODE, as demonstrated by @Sulaymon Eshkabilov. Search 'ode45' in MathWorks and post your code here so that we can check.
function dTJdt = odefcn(t, TJ)
tau = 1; % parameter
TG = sin(2*pi/10*t); % external input
dTJdt = (TG - TJ)/tau; % differential equation
end

类别

Help CenterFile Exchange 中查找有关 Programming 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by