Vary a parameter and plot the output

5 visualizaciones (últimos 30 días)
kasim
kasim el 1 de Abr. de 2020
Comentada: Star Strider el 1 de Abr. de 2020
Hi, I have the following script for which I am trying to determine how the outlet temperature (Tout) varies depending on the solar radiation (I) available. I have tried to set (I) as an array and run the code as a for loop but this doesn't seem to give the desired result. Additionally it doesn't plot (I) against (Tout) at the end. Can anyone provide me with some insight as to how to rectify this. I have attached the code.
Kind regards

Respuesta aceptada

Star Strider
Star Strider el 1 de Abr. de 2020
Try this:
function main
x0 = [500 500 500 500 5 5];
opt = optimset('Display','off'); % 'display', 'iter'
I = [500 550 600 650 700 750]; % Solar radiation
for k = 1:numel(I)
res(k,:) = fsolve(@(x)f(x,I(k)),x0,opt);
% res'
end
figure
plot(I, res(:,3))
grid
xlabel('Solar Radiation')
ylabel('T_{out}')
end
That ran for me without error in R2020a.
  12 comentarios
kasim
kasim el 1 de Abr. de 2020
n =
2.0508 1.8644 1.7090 1.5775 1.4649 1.3672
2.2534 2.0486 1.8778 1.7334 1.6096 1.5023
2.4556 2.2323 2.0463 1.8889 1.7540 1.6370
2.6573 2.4157 2.2144 2.0440 1.8980 1.7715
2.8585 2.5986 2.3821 2.1988 2.0418 1.9056
3.0592 2.7811 2.5493 2.3532 2.1852 2.0395
Apologies, what I was trying to say was that it calculates n for not only Tout, but also Tm,Tp,Tg etc as can be seen by the following code. Is there a way to fix this so it only gives the values corresponding to Tout? i.e. row 3
Star Strider
Star Strider el 1 de Abr. de 2020
The ‘Tout’ value is ‘res(:,3)’. Define it that way (perhaps as ‘Toutv’) and you should get the result you want:
Toutv = res(:,3);
n = m*cp*(Toutv-Tin)./I*A;
That should produce a vector rather than a matrix.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Loops and Conditional Statements en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by