Optimizing for a function output with multiple variables having different ranges.
4 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Josef Woloschek
am 12 Feb. 2019
Kommentiert: Walter Roberson
am 13 Feb. 2019
Hello! I have a function that takes multiple inputs of temperature, pressure and so on to calculate net profit of a steam power plant. I am trying to create a new function that lets me run my first function multiple times with different ranges of my inputs and store or present the results of each iteration.
For example:
function [Net_Profit] = SteamPlant(T1, T2, P1, P2);
% This function would take two temperatures and pressures and output a Net Profit value%
Since it relies on an external function to calculate variables, I can't do "T1 = 35:45:10;" and then run the function. I need to find a way to run my function multiple times with singular input values across a range for each input.
Let me know if you need any clarification or details. I really appreciate the help and or suggestions! (:
0 Kommentare
Akzeptierte Antwort
aara
am 12 Feb. 2019
Bearbeitet: aara
am 12 Feb. 2019
Hi, a for loop would be very useful, you could use it to cycle through all the datapoints you want:
%define T1, T2, P1,P2 Ranges:
T1 = 20:45;
T2 = 30:60;
%place values for P1 and P2
P1 = ...;
P2 = ...;
%you would also require a matrix to place all your results in
%the results would be equal to length(T1)*length(T2)*length(P1)*length(P2).
%define a counter for to store you results:
counter = 1;
for i = 1:length(T1)
for j = 1:length(T2)
for k = 1:length(P1)
for m = 1:length(P2)
NetProfit(counter,:) = SteamPlant(i,j,k,m);
Input_data(counter,:) = [counter, i, j, k, m];
counter = counter+1;
end
end
end
end
This would be very time consuming for large values. It will cycle through all values of P2 at constant P1,T1,T2 then change P1 by one and cycle again through P2. It continues until it has cycled through all values T1.
2 Kommentare
Walter Roberson
am 13 Feb. 2019
I predict you tried to store all of this in SteamPlant.m . When you define a function in a script then the function cannot have the same name as the script .
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Thermal Analysis finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!