Defining function for numerical intergration
Afficher commentaires plus anciens
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!
Réponses (1)
the cyclist
le 3 Fév 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)
Catégories
En savoir plus sur Numerical Integration and Differentiation dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!