Nested functions procedure error
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Hi,
I created some nested function but it reports the error. In the first function, I calculated values for temperatures x1 and x2. Then, I defined function result that represents thermostat which should determine should thermostat be on or off in each iteration. In case that thermostat does not work in each iteration, temperature raise. Here are the functions:
function xprime = heat_sys(t,x);
params...
xprime = (system of diff equat)
function result = thermostat(x);
on = true;
off = false;
for i=1:n(end)
if(x(i,1)>=18 && x(i,1)<=20)
result(i)=on;
else if(x(i,1)<18)
result(i)=on;
else if(x(i,1)>20)
result(i,1)=off;
end;
end;
end;
end;
By the way, is this right approach to do this or I could use something different also?
Thanks in advance!
8 comentarios
Walter Roberson
el 9 de Sept. de 2013
The xprime you are returning does not look to involve values calculated by thermostat(). If it actually does, then you would have the calls in the way you defined your system of equations... e.g.,
xprime = [ .... t^5+thermostat(x), ....]
If, though, the differential equation matrix is not calculated in terms of thermostat calls, then some other layer needs to receive the result of the thermostat calls. What layer is that?
Respuesta aceptada
Walter Roberson
el 9 de Sept. de 2013
I am going to guess that you have missed out on telling us that your heat_sys function is being invoked by ode45 or similar. I am going to further guess that heat_sys is your main function, and that your thermostat function is needed to calculate non-linear constraints. If I am correct, then a handle to your thermostat function would need to be passed as an additional parameter to the ode call, and it would also have to be modified to return information for both equality constraints and inequality constraints (I cannot tell which you intend in your existing code.)
If I am correct so far, please have another look at the documentation for the ode function you are using.
3 comentarios
Walter Roberson
el 9 de Sept. de 2013
Okay so how do the thermostat values actually get used? What takes them as inputs ? Or are they purely constraints (which it doesn't quite sound to me that they are) ?
Más respuestas (0)
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!