1

I have to solve this equation in matlab with ode45 when T is in range [0,12]:

enter image description here

I want that when:

  • T > Tend, switch is 0,
  • (T < Tin and dT/dt > 0), switch is 1.

I see the documentation here but I can't understand how do it.

clc;
clear all;
close all;

global Q Tamb n swicth

Tamb = 0;
Q = 1000;
n = 1/3;
Ti = 0;
swicth = 1;
T_end = 2000;

maxT = 12;
tspan = [0 maxT];
CI = [Ti];

[TOUT,YOUT] = ode45(@odefun,tspan, CI); <--------- ??

odefun function:

function T = odefun(t, Tin)

global Q Tamb n swicth

T = (swicth*Q - (Tin - Tamb)^n);

end

As I said above, I don't want to pass a parameter to a function! Perhaps the previous title was misleading, but I think my question was clear. However I try to explain better. Ode45 numerical integrate my function, so it gives me the value of a function at time t_i (f(t_i)) and this is repeated for each t_i in [0:12]. I want, based on the value of the function at a time t_i, to change the value of the switch for the integration at time t_(i+1).[The rules is explain above].

Fra
  • 69
  • 1
  • 1
  • 7
  • Can you clarify what Tin is? The one you use for changing switch. It that your initial value of T? – user9985 Feb 16 '18 at 14:17
  • [MATLAB: How do I pass a parameter to a function?](https://stackoverflow.com/questions/2256229/matlab-how-do-i-pass-a-parameter-to-a-function) or [this one](http://stackoverflow.com/questions/7680224/matlab-ode45-how-to-change-a-parameter-inside-it-while-calling-it). See also the [relevant documentation](https://www.mathworks.com/help/matlab/ref/ode45.html#bu3uhuk) and [this](http://www.mathworks.com/help/matlab/math/parameterizing-functions.html). In all cases you should not be using global variables for this. – horchler Feb 16 '18 at 14:35

0 Answers0