How to calculate Beta
1 次查看(过去 30 天)
显示 更早的评论
Hi.
I'm trying to calculate Beta for use in a larger equation but have reached a snag. I used the script below but keep receiving this warning 'Attempted to access func(27); index out of bounds because numel(func)=1.' And i'm not sure how to correct for it. Any suggestions would be greatly appreciated.
% Beta = (1/2)*[{(intergral 0, -H) (c-U)^2*phi^2*dz)}/ {(intergral 0, -H)*(c-U)*(d phi/dz)*dz)}]
func=(c-U).^2*(phi.^2)*dz; %Function for top of Beta equation
func_2=(c-U)*(d_phi/dz)*dz; %Function for bottom of Beta equation
ss=length(nz); %Number of data cells of n(z) values
ss1=ss-r+1;
B=zeros(ss1,1); %r(z) => tr(i,1)
B(1,1)=0;
for i=dz:ss1 %Loop function for integral (z,z1) func(z)*dz
B(i,1)=B(i-1,1)+func(i+r-1)*dz;
B2(i,1)=B(i-1,1)+func_2(i+r-1)*dz;
end
0 个评论
回答(3 个)
John D'Errico
2013-12-18
You created func as a scalar variable. I.e., it has only one element.
Then you try to index into it, with an index that is not 1. In fact, it appears to be your index was 27. I wonder what happens then? Read the error message. It told you exactly what the problem was.
0 个评论
Niklas Nylén
2013-12-18
编辑:Niklas Nylén
2013-12-18
When you write func = ... you create a variable named func calculated from the values of your parameters (c, U, phi, dz), the error you get is that you try to access element number 27 in the variable func, although func only has one single element.
Have a look at the trapz function: http://www.mathworks.se/help/matlab/ref/trapz.html or on the integral function (introduced in Matlab 2012a): http://www.mathworks.se/help/matlab/ref/integral.html?s_tid=int_b_int#btdd9x5
0 个评论
Bjorn Gustavsson
2013-12-18
I think you want to create a function-handle/anonymous function/dynamic function. See
help function_handle
HTH
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!