MATLAB: Equating Two Unknowns Using a Given Range for Each.

satisying an equation.

Basically, I have a Temperature range and an entropy range. I want the function to find the best suitable(approximate) temperature in the right hand side using the given range to equal the entropy on the left hand side. Entropy has to be in the range given to satisfy the equation.
T = linspace(100,293,1000); %Temperature
S = linspace(0, 10,1000); %Entropy
Cp= 35.56; %Heat Cap. @ const. P
R = 8.314; %IG Const.
S = Cp*log(T./293)-R*log(97.87./500)+9.2
Thank you in advance.

Best Answer

It is not clear why you create S with linspace() but then overwrite S with the result of the calculation?
Possibly you mean the final line as a kind of equality that has to be satisfied, that for each left hand side value, you want to find the location on the right that most nearly equals it. If so then,
Scalc = Cp*log(T./293)-R*log(97.87./500)+9.2;
tempidx = interp1(S, 1:length(S), Scalc, 'nearest', NaN);
The locations at which the Scalc is outside of the linspace() will have a result of NaN, and the other locations will have the index of the T.
You could easily calculate exact temperatures instead of approximate. Algebraically,
S = Cp*log(t/293) - R * log(97.87/500) + 9.2 implies
S - 9.2 + R * log(97.87/500) = Cp * log(t/293) implies
(S - 9.2 + R * log(97.87/500)) / Cp = log(t/293) implies
exp((S - 9.2 + R * log(97.87/500)) / Cp) = t/293 implies
t = 293 * exp((S - 9.2 + R * log(97.87/500)) / Cp)
and that last line is also valid code.