Error in fzero usage
Afficher commentaires plus anciens
Hi! MATLAB Query: I have written an exercise in m file for some design parameters of a heat exchangers. On running the m file, the error message reads as below in the command window. Can someone help as to what is wrong? Thanks.
quote ??? Error using ==> fzero at 317 FZERO cannot continue because user supplied function_handle ==> T2HotSide failed with the error below.
The number of sites, 8, is incompatible with the number of values, 7.
Error in ==> HeatExchanger at 12 Th2=fzero(@T2HotSide,Th1+15,options); unquote
Réponses (4)
Fangjun Jiang
le 8 Août 2011
0 votes
"The number of sites, 8, is incompatible with the number of values, 7." This message seems to be an error message from that particular function T2HotSide(). Sounds to me that that there are 8 sites specified but only 7 valules are provided.
Searching for the phrase "The number of sites", or "is incompatible with the number of values" in T2HotSide.m might help you to find the where the error occurred. Also, put a break point in T2HotSide.m and step through will pinpoint exactly which line the error occurred.
Walter Roberson
le 8 Août 2011
0 votes
Is Th1 indeed a vector with at least 8 values?
Rajoo Balaji
le 8 Août 2011
4 commentaires
Walter Roberson
le 8 Août 2011
What is WaterProperties? And what are the size and shape of the other variables?
If any of your variables are vectors or matrices, make sure you use .* and ./ instead of * and / or else you will get different results than you expect.
I suggest you put a breakpoint in T2HotSide and single-step through it and see where it creates an error. There isn't anything _obvious_.
Note: it is considered better to use anonymous functions to pass in additional variables to fzero, rather than to use global variables.
Rajoo Balaji
le 8 Août 2011
Walter Roberson
le 8 Août 2011
To check: each call to WaterProperties returns a vector of 8 values? If so then your Th expression would be calculating based upon two vectors, but the expression needs to return a single value out of T2HotSide . As the constants (Tc2-Tc1) and ms could be moved in the expression, if cph and cpc are indeed vectors, you would effectively have cph / cpc with the "/" being the mrdivide operator, which would be more or less cph * pinv(cpc) with the * indicating matrix multiplication. Are you sure that is what you want?
Rajoo Balaji
le 10 Août 2011
Fangjun Jiang
le 8 Août 2011
0 votes
Watch this video: http://blogs.mathworks.com/videos/2010/09/02/using-debugger-to-walk-through-code/ for basic code debugging techniques. Many problem can be easily solved if you know how to step and observe the value of the variables.
1 commentaire
Rajoo Balaji
le 10 Août 2011
Catégories
En savoir plus sur Downloads dans Centre d'aide et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!