Vary a parameter and plot the output

5 views (last 30 days)
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

Accepted Answer

Star Strider
Star Strider on 1 Apr 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 Comments
kasim
kasim on 1 Apr 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 on 1 Apr 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.

Sign in to comment.

More Answers (0)

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!