Defining function for numerical intergration

조회 수: 10 (최근 30일)
Holly Miller
Holly Miller 2013년 2월 3일
Hi All, I am new to Matlab and I am trying to define a function f=1/x and then compare the results of various numerical integration methods (quad, trapz, simpsons) from 0-1. I have entered my function in a new .m filed called f.m with the following: function y = f(x) y = 1 .* (x.^-1);
Then when I try to do the numerical integration methods I continually get errors relating to x, either it being undefined or saying the matrix must be square.
Any tips on how to define the variable x or to avoid these errors?
Thanks!

답변 (1개)

the cyclist
the cyclist 2013년 2월 3일
I had no problem using quad() like this:
Here is what my file f.m looks like:
function y = f(x)
y = 1.*(x.^-1);
Here is how I called it from the command line:
>> quad(@f,1,2)

카테고리

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