How to calculate Beta
3 ビュー (過去 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!