Defining function for numerical intergration
9 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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!
0 Kommentare
Antworten (1)
the cyclist
am 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)
0 Kommentare
Siehe auch
Kategorien
Mehr zu Numerical Integration and Differentiation finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!