How can I get the plot correctly?
조회 수: 1 (최근 30일)
이전 댓글 표시
Hello,
I write some code like this:
vx = 30:10:300;
vy = 2:0.04:3;
[xx,yy] = meshgrid(vx,vy);
zz = get_critical_value(yy,xx,0.05);
surf(xx,yy,zz)
Unfortunately, Matlab returns some feedback messages below:
======================================================
FZERO cannot continue because user-supplied function_handle ==>
@(czero)integral(@(y)fun(y,czero),0,3*Cp*sqrt(n))-alpha failed with the error below.
Inner matrix dimensions must agree.
Error in get_critical_value (line 15)
czero_sol = fzero(@(czero) integral(@(y)fun(y,czero),0,3*Cp*sqrt(n))-alpha,czero_guess);
======================================================
What's wrong with my program? How can I solve this situation to get the right plot? Thanks!
*The code of get_critical_value:
function czero_sol = get_critical_value(C,n,alpha)
if n<100
Cp = C+0.33;
else
Cp = C+0.12;
end
fun = @(y,czero)chi2cdf((n-1)*(3*Cp*sqrt(n)-y).^2/(9*n*czero^2),n-1).*(normpdf(y+3*(Cp-C)*sqrt(n))+normpdf(y-3*(Cp-C)*sqrt(n)));
czero_guess = 1;
czero_sol = fzero(@(czero) integral(@(y)fun(y,czero),0,3*Cp*sqrt(n))-alpha,czero_guess);
end
댓글 수: 0
채택된 답변
Robert
2017년 8월 23일
Your function get_critical_value is not build to handle array inputs. It is always nice if you can vectorize your function to take advantage of MATLAB's fast array operations but in your case, integral and fzero will make this difficult.
Instead of vectorizing, you could perform the operation one-at-a-time using arrayfun
vx = 30:10:300;
vy = 2:0.04:3;
[xx, yy] = meshgrid(vx, vy);
zz = arrayfun(@(y, x) get_critical_value(y, x, 0.05), yy, xx);
surf(xx, yy, zz)
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Fit Postprocessing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!