As has been said, this line has invalid MATLAB code:
Ta = Tinf+ (Tb-Tinf)cosh(m(L-xa))/cosh(m*L);
You need to learn about operators in MATLB. If you don't use them, then your code won't work. MATLAB does not just assume multiplication when no * operator is present. In fact, it assume that you are trying to do something else, and then it tiries to make sense of what you wrote.
What does that mean? You apparently want to MULTIPLY the sub-terms m and (L-xa). I claim that, because m appears to be a constant. Does MATLAB know that m(L-xa) means multiplication? OF COURSE NOT. MATLAB cannot read your mind. Instead, it looks at that expression, and thinks, hmm. m is a variable. I guess they want me to index the variable m, thus finding element with index (L-xa). After all, you did say that you got an error telling you that "Array indices must be positive integers or logical values."
So if you know that you want to multiply, then use * or .* as appropriate! Don't ask MATLAB to read your mind.
Similarly, what does this mean?
(Tb-Tinf)cosh(m(L-xa))
Did you want to multiply the terms (Tb-Tinf) and cosh(m(L-xa))? Did you use * or .* there? Should MATLAB know what you want? Should it read your mind? NO. (Well, some think it should, but computers are not that smart, not yet. I'm not even sure I want them to be that smart.)
Look at the error message. What does it say? It points at the point between the two parens in that expression. (If you fix this, so it will get past that point, it would next start complaining about m, but it fails before it ever gets there, as youtr code stands now.)
So how should you modify that line? Use operators when you want to multiply things! After all, you know that you need to use / when you want to divide, + when you want to add, - when you want to subtract. Is multiplication a second class citizen among operators?
Ta = Tinf+ (Tb-Tinf)*cosh(m*(L-xa))/cosh(m*L);
Finally, make sure you know the difference between * and .*, ^ and .^, and / and ./, if there are vectors and arrays involved, as otherwise your next question willl again be why does my code not work.
Best Answer