Sirs, I have something like the below formula:
T=(A+B+C)+(D*T) dt where A, B and C are vectors with let me say (1,6000) length How Can I integrate this formula using ODE45, please help, and thanks in advance

 Accepted Answer

x0 = ... something same length as A;
[T, X] = ode45( @(t, x) f(t, X, A, B, C, D), tspan, x0);
function dy = f(t, y, A, B, C, D)
dy = (A + B + C) + (D*t);
... except of course if that were really your formula you would construct
x0 = ... something same length as A;
ApBpC = A + B + C;
[T, X] = ode45( @(t, x) f(t, X, ApBpC, D), tspan, x0);
function dy = f(t, y, ApBpC, D)
dy = ApBpC + (D*t);

11 Comments

Thanks Mr. Walter..
I will re-arrange the equation just in case this make a difference
Temp/dt=(A+B+C)+(D*Temp) I estimated the initial value of (Temp) D: is a constant dt: time interval
Could you confirm that the form of the equation is
T(t) = (A+B+C) + (D*T(t))*diff(T(t),t)
If it is, then provided that you meet the theoretical boundary conditions, this has two solutions:
1)
T(t) = A + B + C %that is, constant in time
or 2)
T(t) = (lambertw(0, exp(-(A + B + C - t/D - (log(-exp(-(A + B + C - T0)/(A + B + C))*(A + B + C - T0)) + 1)*(A + B + C))/(A + B + C))/(A + B + C)) + 1)*(A + B + C)
where T0 is the boundary value at T(0)
T(t)=(A/dt+B/dt+C/dt)+D(T/dt);
A,B and C has been calculated by another algorithm in the script for(6000,1) length, and just(D= constant number)
So to confirm,
T(t) == (A / diff(T(t),t) + B / diff(T(t),t) + C / diff(T(t),t)) + D * T(t) ./ diff(T(t),t)
? Which would simplify in part to (A+B+C)/diff(T(t),t) and then A+B+C, all being constants, could be replaced with the sum of the three?
When I see A/dt I tend to think you intend that A is a function of t and that you are expressing its derivative there, an operation that would more typically be expressed as dA/dt . But if that were the case then it is not clear why you would have a vector of constants for A.
sorry for making you miss understanding me, Dear Sir A,B and C varying with time, that have a value at each time step (t), and they are estimated previously, so for run time of(16000 second) I have the values of A,B and C for each time step, what you wrote is right (dA/dt)
T(t)=(dA/dt+dB/dt+dC/dt)+D(T/dt);
size(dA/dt) =(16000,1) and also dB/dt and dC/dt
Are A, B, C intended to be tables to be linearly interpolated at the real times, along the lines of
this_A = interp1(times_A_was_sampled_at, A, t); %estimate at current time
? If so then there would be concern about whether the prior estimation and the interpolation would work together to produce values with continuous first derivatives; if not then you need to use a different approach because ode45() cannot support "jumps" at all.
Dear Walter, it is really difficult to me , but I tried this, insert a loop inside the ODE45, is it correct, also it going to be very slow
global : A B C
for i=1:10:t
Tdot=((A(i)+B(i)+C(i))-(T);
end
F1T=[Tdot];
end
In your "for i" loop, you overwrite all of Tdot. The effect is going to be the same as if you had only done the last of the iterations.
You should avoid using global: global are the slowest form of variables. https://www.mathworks.com/help/matlab/math/parameterizing-functions.html
how to develope the loop? to avoid overwriting a previues values?
i_vals = 1 : 10 : t;
num_i = length(i_vals);
Tdot = zeros(num_i, 1);
for i_idx = 1 : num_i
i = i_vals(i_idx);
Tdot(i_idx) = A(i) + B(i) + C(i) - T;
end
result = TDot;
Note that the resulting value changes length as t increases. If t represents the time parameter to the ode, then this would mean that you are trying to return a different number of derivatives as time goes on.

Sign in to comment.

More Answers (0)

Categories

Find more on Programming in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!