Problem with fsolve - several errors

Trying to use fsolve to solve a system of two equations - unknowns are H2 and Ts2.
this is the function:
function [F] = SystemProb1(X)
H2 = X(1);
Ts2 = X(2);
F(1) = 'H2*(w*h*n)*(Ts2-Ta) + Om*(w*h*n)*e*(((Ts2+460)^4)-((Ta+460)^4)) - ((w*h*n)*(Ti-Ts2)/(R1+R))';
F(2) = 'H2-0.19*(Ts2-Ta)^0.33';
end
I am running it by including this line in my script:
[X] = fsolve(@SystemProb1, [0 100]);
with 100 and 0 being my approximate "guesses" for H2 and Ts2.
These are the errors I get:
Unable to perform assignment because the indices on the left side are not compatible with the size of the right side.
Error in SystemProb1 (line 4)
F(1) = 'H2*(w*h*n)*(Ts2-Ta) +
Om*(w*h*n)*e*(((Ts2+460)^4)-((Ta+460)^4)) -
((w*h*n)*(Ti-Ts2)/(R1+R))';
Error in fsolve (line 242)
fuser = feval(funfcn{3},x,varargin{:});
Error in ProcessHeatingHWProb1 (line 26)
[X] = fsolve(@SystemProb1, [0 100]); %guessed values
Caused by:
Failure in initial objective function evaluation. FSOLVE cannot
continue.
Really trying to figure this out because I modeled it off of how I have used fsolve in other examples but it just won't work! Any help or recommendations are appreciated

Answers (1)

Matt J
Matt J on 5 Nov 2018
Edited: Matt J on 6 Nov 2018
Remove the quotes from your expressions for F(1) and F(2)
F(1) = H2*(w*h*n)*(Ts2-Ta) + Om*(w*h*n)*e*(((Ts2+460)^4)-((Ta+460)^4)) - ((w*h*n)*(Ti-Ts2)/(R1+R)) ;
F(2) = H2-0.19*(Ts2-Ta)^0.33 ;
Also, pass the various known constants to the function as described here.

2 Comments

Thank you I just figured that out right before you responded - I modeled the setup off of an example from class in which we used single quotes - not honestly sure why. Thank you!
You're welcome, but please Accept-click the answer.

Sign in to comment.

Categories

Find more on Programming in Help Center and File Exchange

Products

Release

R2018a

Asked:

on 5 Nov 2018

Commented:

on 6 Nov 2018

Community Treasure Hunt

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

Start Hunting!