Numerical integration using a quad function

I have created the following function
function x = rZSum(y, z)
y= load('delta.txt');
z = load('aSqr.txt');
x = y./z;
end
I would now like to use this function in numerical integration, evaluating it between 0 and 0.9999.
I have tried both
quad(rZSum,0,0.9999)
and
quadl(rZSum,0,0.9999)
with the same error being thrown up each time
Error using fcnchk (line 103)
FUN must be a function, a valid string expression, or an inline function object.
Would anyone be able to guide me on where I am going wrong, or what the error means? As integrating in matlab is new to me. Thank you in advanced!

댓글 수: 4

For what you’re doing you probably don’t need a function anyway.
I suggest you first load 'delta.txt' and aSqr.txt' (or use one of the file reading functions like textscan), depending on the kind of files those are. You need to get the numerical values into the workspace first.
Then create x.
The trapz function might be more appropriate here.
If that is your actual code and function call, you need to pass parameters y and z to you function rZSum
func(rZSum(y,z),0,0.9999)
fcnchk is trying to validate your function call and failing.
Thank you for the help, however when I run
func(rZSum(y,z),0,0.9999)
The following error is now being thrown up
Undefined function or variable 'y'.
And when I try to use
trapz(rZSum,0,0.9999)
the following error is being thrown up
Error using trapz (line 55)
X must be a vector.
I feel silly about not catching this earlier, but if you're still having problems, you need to change the definition of your function. Since you load y and z from inside the function, you need to remove them as parameters from the function definition.

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

도움말 센터File Exchange에서 Numerical Integration and Differentiation에 대해 자세히 알아보기

질문:

Amy
2014년 3월 14일

댓글:

2014년 5월 15일

Community Treasure Hunt

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

Start Hunting!

Translated by