How to calculate Beta
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
Respuestas (3)
John D'Errico
el 18 de Dic. de 2013
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 comentarios
Niklas Nylén
el 18 de Dic. de 2013
Editada: Niklas Nylén
el 18 de Dic. de 2013
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 comentarios
Bjorn Gustavsson
el 18 de Dic. de 2013
I think you want to create a function-handle/anonymous function/dynamic function. See
help function_handle
HTH
0 comentarios
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!