Defining function for numerical intergration

13 views (last 30 days)
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!

Answers (1)

the cyclist
the cyclist on 3 Feb 2013
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)

Community Treasure Hunt

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

Start Hunting!