MATLAB Answers

Why is the output of my function infinity?

6 views (last 30 days)
Nicholas Gillam
Nicholas Gillam on 7 Apr 2019
Answered: Torsten on 8 Apr 2019
I'm doing code for the trapezoidal rule. I checked my code with simple functions at first to make sure it was outputting correctly. However when I am attempting what I need to do, my output says it's infinity, when it should not be. The solution I got from Wolfram Alpha and my TI89 was 0.00958. Could it be the "1/n" in the x definition? I needed 10 steps for the trapezoids I'm setting up.
The function being applied is: cos^2((pi*cos(x))/2)*csc(x).
n = 10;
x = 0:1/n:1/2;
y=cos((pi*cos(x))/2).^2.*csc(x);
z=trapz(x,y)

  0 Comments

Sign in to comment.

Answers (2)

Star Strider
Star Strider on 7 Apr 2019
The cosecant is , so at integral multiples of π (such as 0, π, ...) the cosecant will approach .

  4 Comments

Show 1 older comment
Star Strider
Star Strider on 7 Apr 2019
n = 10;
x = 0:1/n:1/2;
Your upper limit of integration changes nothing, unfortunately.
Note that is — and will likely always be — .
Nicholas Gillam
Nicholas Gillam on 7 Apr 2019
Hmm, there must be something I can do to simplify it, especially if Wolfram Alpha and my TI89 are giving me a finite number.
Star Strider
Star Strider on 8 Apr 2019
Wolfram Alpha and your Ti89 are wrong.

Sign in to comment.


Torsten
Torsten on 8 Apr 2019
Since your function tends to 0 as x -> 0 by L'Hospital, you can integrate
y = cos((pi*cos(x))/2).^2.*csc(x).*(x > 0);

  0 Comments

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!

Translated by