Integral -> "First input argument must be a function handle"

6 vues (au cours des 30 derniers jours)
Anke Kügler
Anke Kügler le 26 Sep 2015
Commenté : Star Strider le 26 Sep 2015
Dear all,
I'm completly new to MATLAB and am learning as I'm going. I need it for class and homework. No I have the following issue. I have a function and need to calculate the integral, but it returns me an error and I don't know why. Here is the code:
b=(cn-c0)/(zn-z0);
%w=zn+c0/b;
xmin=c0/b;
xmax=zn+c0/b;
r=(a*b*(zn+cn/b))/sqrt(1-power(a,2)*power(b,2)*power(zn+cn/b,2));
rx=integral(r,xmin,xmax)
c0, cn, z0, zn and a will all bit entered (I saved the above part as a script).
Thank you very much in advance!

Réponses (1)

Star Strider
Star Strider le 26 Sep 2015
Modifié(e) : Star Strider le 26 Sep 2015
From what you wrote, you’re integrating over ‘b’, so convert your ‘r’ to an anonymous function:
r = @(b) (a.*b.*(zn+cn./b))./sqrt(1-power(a,2).*power(b,2).*power(zn+cn./b,2));
rx = integral(r,xmin,xmax)
Assuming I guessed correctly, that should work. I vectorised your equation as well. (I did not test this code.)
  2 commentaires
Star Strider
Star Strider le 26 Sep 2015
Anke Kügler’s Answer moved here...
Thank you, that helped a lot! It also made me relize I made a mistake in my function ;)
Thanks again. As I said, I'm still learning MATLAB.
Star Strider
Star Strider le 26 Sep 2015
My pleasure.
The sincerest expression of appreciation here on MATLAB Answers is to Accept the Answer that most closely solves your problem.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Programming dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by