Error in fzero usage
이전 댓글 표시
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
답변 (4개)
Fangjun Jiang
2011년 8월 8일
0 개 추천
"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
2011년 8월 8일
0 개 추천
Is Th1 indeed a vector with at least 8 values?
Rajoo Balaji
2011년 8월 8일
댓글 수: 4
Walter Roberson
2011년 8월 8일
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
2011년 8월 8일
Walter Roberson
2011년 8월 8일
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
2011년 8월 10일
Fangjun Jiang
2011년 8월 8일
0 개 추천
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.
카테고리
도움말 센터 및 File Exchange에서 Downloads에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!