A and B must be floating-point scalars.

조회 수: 4 (최근 30일)
K Dani
K Dani 2018년 4월 18일
답변: Walter Roberson 2018년 4월 18일
I am trying to compute this function(as seen in the attachment) within a for loop but I keep getting an error. Here is my code so far
for n = 1:np
fun = @(br2, brend) (A0./Area).^(0.36)
chi = integral(fun,min(br2), max(brend))
plot(chi, Y)
end
I'm quite certain I just really don't understand how the integral function works or something. "br2" and "brend" are column vectors so I put the boundaries as the min(br2) and max(brend), which makes sense for what I am trying to compute. I think I'm getting the variable part wrong when defining the function to integrate?

답변 (1개)

Walter Roberson
Walter Roberson 2018년 4월 18일

Your fun is a function of two variables, but integral is for functions of one variable.

Your fun is ignoring both inputs and returning a constant value.

Your br2 and brend would have to be numeric floating point values to use in the way you are. class(br2) and class(brend) would need to be 'single' or 'double'.

You are computing a single chi for each iteration, and using it as the x value for plotting Y, which is of unknown size. You might not get any output. You should probably be recording the chi results into a vector and plotting them afterwards, such as

chi(n) = integral(....);

and then after the loop,

plot(chi)

카테고리

Help CenterFile Exchange에서 Numerical Integration and Differentiation에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by