integral with (sin x)^4

Hi, i'd appreciate if anybody could help.
I am trying to integrate this function from 0 to 0.2985
x = linspace(0,0.2985,1000);
y=1/sqrt((1-power(sin(x),4)\0.0865^2));
simps(x,y)
simps(x,y) is a another function that will calculate the integral of y over x. For some reason, when I change the division of linspace (say from 1000 to 500), the result of the simps(x,y) changes significantly.
I think there is something wrong with the line x = linspace(0,0.2985,1000); I don't know to change that line to what.
function simps(x,y) is verified correct by integrating other functions already. It is integration by simpson rule. I have tried double, quad, quad8 but unsuccessful.

Réponses (1)

Mike Hosea
Mike Hosea le 12 Juil 2013

0 votes

You have two errors. One, you need 1./sqrt instead of 1/sqrt. Second, you have \0.0865^2 instead of /0.0865^2. Here is how to define an anonymous function.
>> f=@(x)1./sqrt((1-power(sin(x),4)/0.0865^2));
>> integral(f,0,0.2985)
ans =
0.390930321219332

3 commentaires

zamri
zamri le 12 Juil 2013
Dear Mike,
Thanks for your answer. However I have copied your codes and it doesn't give similar answer,
>> clear
>> f=@(x)1./sqrt((1-power(sin(x),4)/0.0865^2));
>> integral(f,0,0.2985)
??? Undefined function or method 'integral' for input
arguments of type 'function_handle'.
zamri
zamri le 12 Juil 2013
ops, I'm sorry, I suppose I'll just try it in 2012a. thanks Sir.
Mike Hosea
Mike Hosea le 12 Juil 2013
You can substitute quad or quadl there in an earlier release. I don't like to use these functions in my answers because QUAD and QUADL are now deprecated. You can also use QUADGK.

Connectez-vous pour commenter.

Catégories

Question posée :

le 12 Juil 2013

Community Treasure Hunt

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

Start Hunting!

Translated by