matlab not displaying an approximated value of an improper integral? (2024)

9 views (last 30 days)

Show older comments

Lahcen on 23 Aug 2023

  • Link

    Direct link to this question

    https://support.mathworks.com/matlabcentral/answers/2011812-matlab-not-displaying-an-approximated-value-of-an-improper-integral

  • Link

    Direct link to this question

    https://support.mathworks.com/matlabcentral/answers/2011812-matlab-not-displaying-an-approximated-value-of-an-improper-integral

Moved: John D'Errico on 28 Aug 2023

Accepted Answer: Nathan Hardenberg

I want to calculate an approximate value of an improper integral:

>> fun= 4./(x.*(1-x).*(2-x).*(pi.^2+(log(x./(1-x)).^2))

>> vpa(int(fun,0,1))

then matlab displays the result:

ans =

vpaintegral(4/(x*(log(-x/(x - 1))^2 + 2778046668940015/281474976710656)*(x - 1)*(x - 2)), x, 0, 1).

how can I get the approximate value of this improper integral? thanks in advance.

6 Comments

Show 4 older commentsHide 4 older comments

Nathan Hardenberg on 23 Aug 2023

Direct link to this comment

https://support.mathworks.com/matlabcentral/answers/2011812-matlab-not-displaying-an-approximated-value-of-an-improper-integral#comment_2858517

  • Link

    Direct link to this comment

    https://support.mathworks.com/matlabcentral/answers/2011812-matlab-not-displaying-an-approximated-value-of-an-improper-integral#comment_2858517

Open in MATLAB Online

Hey Lahcen, I can not reproduce your results. Your fun variable is not correct. It seems there is a bracket missing at the end. But if I add it I do not get the answer you got. Have you done something beforehand? Can you show how you defined x and p? And make sure to "clear 'all'" at the start of the script

clear 'all'

syms x p

fun= 4./(x.*(1-x).*(2-x).*(p.^2+(log(x./(1-x)).^2))) % added bracket at the end

fun=

matlab not displaying an approximated value of an improper integral? (3)

vpa(int(fun,0,1))

ans=

matlab not displaying an approximated value of an improper integral? (4)

Dyuman Joshi on 23 Aug 2023

Direct link to this comment

https://support.mathworks.com/matlabcentral/answers/2011812-matlab-not-displaying-an-approximated-value-of-an-improper-integral#comment_2858547

  • Link

    Direct link to this comment

    https://support.mathworks.com/matlabcentral/answers/2011812-matlab-not-displaying-an-approximated-value-of-an-improper-integral#comment_2858547

Edited: Dyuman Joshi on 23 Aug 2023

Open in MATLAB Online

"But if I add it I do not get the answer you got"

If you check the term given by OP as the result and the final output of your code, they are the same (with a value substituted for p)

@Lahcen

You can try solving numerically, but as there are singularities at x==0 and x==1, the result will not be accurate -

%p^2 value taken from above

p2=2778046668940015/281474976710656;

fun= @(x) 4./(x.*(1-x).*(2-x).*(p2+(log(x./(1-x)).^2)));

integral(fun,0,1)

Warning: Minimum step size reached near x = 1. There may be a singularity, or the tolerances may be too tight for this problem.

ans = 2.7246

Nathan Hardenberg on 23 Aug 2023

Direct link to this comment

https://support.mathworks.com/matlabcentral/answers/2011812-matlab-not-displaying-an-approximated-value-of-an-improper-integral#comment_2858552

  • Link

    Direct link to this comment

    https://support.mathworks.com/matlabcentral/answers/2011812-matlab-not-displaying-an-approximated-value-of-an-improper-integral#comment_2858552

Open in MATLAB Online

@Dyuman Joshi good catch. I saw that but did not realise that p is probably just this numerical value then

p = 2778046668940015/281474976710656

p = 9.8696

Lahcen on 23 Aug 2023

Direct link to this comment

https://support.mathworks.com/matlabcentral/answers/2011812-matlab-not-displaying-an-approximated-value-of-an-improper-integral#comment_2858712

  • Link

    Direct link to this comment

    https://support.mathworks.com/matlabcentral/answers/2011812-matlab-not-displaying-an-approximated-value-of-an-improper-integral#comment_2858712

I'm sorry, it's pi not p.

Dyuman Joshi on 23 Aug 2023

Direct link to this comment

https://support.mathworks.com/matlabcentral/answers/2011812-matlab-not-displaying-an-approximated-value-of-an-improper-integral#comment_2858732

  • Link

    Direct link to this comment

    https://support.mathworks.com/matlabcentral/answers/2011812-matlab-not-displaying-an-approximated-value-of-an-improper-integral#comment_2858732

Open in MATLAB Online

I had an inkling because of the value but wasn't sure due to the format of the value -

sqrt(2778046668940015/281474976710656)

ans = 3.1416

Lahcen on 24 Aug 2023

Direct link to this comment

https://support.mathworks.com/matlabcentral/answers/2011812-matlab-not-displaying-an-approximated-value-of-an-improper-integral#comment_2862767

  • Link

    Direct link to this comment

    https://support.mathworks.com/matlabcentral/answers/2011812-matlab-not-displaying-an-approximated-value-of-an-improper-integral#comment_2862767

Moved: John D'Errico on 28 Aug 2023

Thank you al, Mr Nathan Hardenberg, Mr Dyuman Joshi and Mr Steven Lord, for your helpful responses in addressing my improper integral calculation issue on the Matlab forum. Your assistance was greatly appreciated!. Indeed, I worked by the idea of Mr Nathan Hardenberg.

I'd also like to note that the integral in question is convergent, whereas the numerical methods provided by Matlab seem to be getting stuck without yielding the desired result. It appears that there is a need for the development of more reliable numerical techniques.

Many thanks.

Sign in to comment.

Sign in to answer this question.

Accepted Answer

Nathan Hardenberg on 23 Aug 2023

  • Link

    Direct link to this answer

    https://support.mathworks.com/matlabcentral/answers/2011812-matlab-not-displaying-an-approximated-value-of-an-improper-integral#answer_1292247

  • Link

    Direct link to this answer

    https://support.mathworks.com/matlabcentral/answers/2011812-matlab-not-displaying-an-approximated-value-of-an-improper-integral#answer_1292247

Edited: Nathan Hardenberg on 23 Aug 2023

Open in MATLAB Online

Here are some ideas, but please still regard my comment.

  1. You have two variables x and p. You can not approximate numerically then.
  2. "To approximate integrals directly, use vpaintegral instead of vpa. The vpaintegral function is faster and provides control over integration tolerances." [source]
  3. Specify that you want to use x as your variable (int(fun, x, [a b]))
  4. You can not numerically approximate if your denomenator gets 0 at some point (see example below)

-- EDIT --

Your problem is nr. 4. Your denomenator gets 0 to fix this you can simply choose values close to 0 and 1. See example below:

syms x

p = pi; % edited to be p = pi

fun = 4./(x.*(1-x).*(2-x).*(p.^2+(log(x./(1-x)).^2)))

fun=

matlab not displaying an approximated value of an improper integral? (11)

vpa(int(fun, 0.001, 0.999)) % choosing values slightly above 0 and below 1

ans=

2.0701395395280001703925025323768

But maybe this is not good enough, since the solution can get quite a bit different when getting closer to the limits:

vpa(int(fun, 1e-110, 1 - 1e-13)) % choosing tighter values

ans=

2.7443512001078913067737891865659

-- EDIT END --

syms x

f = 1/x;

Fvpaint = vpaintegral(f,x,[0 1])

Error using sym/vpaintegral
Failed precision goal. Try using 'MaxFunctionCalls'.

8 Comments

Show 6 older commentsHide 6 older comments

Steven Lord on 23 Aug 2023

Direct link to this comment

https://support.mathworks.com/matlabcentral/answers/2011812-matlab-not-displaying-an-approximated-value-of-an-improper-integral#comment_2858887

  • Link

    Direct link to this comment

    https://support.mathworks.com/matlabcentral/answers/2011812-matlab-not-displaying-an-approximated-value-of-an-improper-integral#comment_2858887

Open in MATLAB Online

Let's look at how your function behaves over the limits of integration. I had to add one extra closing parenthesis, which I did at the end. I'm not sure if that's the right place for it.

syms x

fun= 4./(x.*(1-x).*(2-x).*(pi.^2+(log(x./(1-x)).^2)))

fun=

matlab not displaying an approximated value of an improper integral? (13)

fplot(fun, [0 1])

matlab not displaying an approximated value of an improper integral? (14)

That certainly looks like a singularity at x = 1.

try

vpa(subs(fun, x, 1))

catch ME

fprintf('subs threw an error:\n%s', ME.message)

end

subs threw an error:Division by zero.

The value at x = 0 also looks like it's potentially very, very large (if not infinite.)

try

vpa(subs(fun, x, 0))

catch ME

fprintf('subs threw an error:\n%s', ME.message)

end

subs threw an error:Division by zero.

What would I get if I tried to numerically integrate the function?

f = matlabFunction(fun)

f = function_handle with value:

@(x)4.0./(x.*(log(-x./(x-1.0)).^2+9.869604401089358).*(x-1.0).*(x-2.0))

integral(f, 0, 1)

Warning: Minimum step size reached near x = 1. There may be a singularity, or the tolerances may be too tight for this problem.

ans = 2.7246

What do you think the value of this integral should be and why?

Lahcen on 24 Aug 2023

Direct link to this comment

https://support.mathworks.com/matlabcentral/answers/2011812-matlab-not-displaying-an-approximated-value-of-an-improper-integral#comment_2859262

  • Link

    Direct link to this comment

    https://support.mathworks.com/matlabcentral/answers/2011812-matlab-not-displaying-an-approximated-value-of-an-improper-integral#comment_2859262

It is convergent, according to Bertrand's criterion.

Dyuman Joshi on 24 Aug 2023

Direct link to this comment

https://support.mathworks.com/matlabcentral/answers/2011812-matlab-not-displaying-an-approximated-value-of-an-improper-integral#comment_2859462

  • Link

    Direct link to this comment

    https://support.mathworks.com/matlabcentral/answers/2011812-matlab-not-displaying-an-approximated-value-of-an-improper-integral#comment_2859462

@Lahcen Can you show the calculations you used to determine that the integral in question is convergent via Bertrand's criterion?

Lahcen on 24 Aug 2023

Direct link to this comment

https://support.mathworks.com/matlabcentral/answers/2011812-matlab-not-displaying-an-approximated-value-of-an-improper-integral#comment_2860557

  • Link

    Direct link to this comment

    https://support.mathworks.com/matlabcentral/answers/2011812-matlab-not-displaying-an-approximated-value-of-an-improper-integral#comment_2860557

Edited: Lahcen on 25 Aug 2023

@Dyuman Joshi: Dear Dyuman, I apologize for the delay in response.

Recall that:

By Bertrand, let a<0,matlab not displaying an approximated value of an improper integral? (18) converge if and only if matlab not displaying an approximated value of an improper integral? (19)or (matlab not displaying an approximated value of an improper integral? (20))

Now, in the vicinity of 0, we have

matlab not displaying an approximated value of an improper integral? (21), which converges according to Bertrand's criterion.

For 1, it suffices to set x=1-t to find

matlab not displaying an approximated value of an improper integral? (22), which converges according to Bertrand's criterion.

whence the integral is convergent.

Lahcen on 25 Aug 2023

Direct link to this comment

https://support.mathworks.com/matlabcentral/answers/2011812-matlab-not-displaying-an-approximated-value-of-an-improper-integral#comment_2860587

  • Link

    Direct link to this comment

    https://support.mathworks.com/matlabcentral/answers/2011812-matlab-not-displaying-an-approximated-value-of-an-improper-integral#comment_2860587

Edited: Lahcen on 25 Aug 2023

@Nathan Hardenberg

Thank you very much for the idea of the approximation, I based on your idea. Indeed, I noticed that the approximation via matlab in the vicinity of 0 does not present a problem matlab not displaying an approximated value of an improper integral? (24) while in the vicinity of 1 Matlab only approached 1 approximately matlab not displaying an approximated value of an improper integral? (25), so I split the integral into two parts as follows:

matlab not displaying an approximated value of an improper integral? (26)

then I made a change of variable for the second integral t=1-x, we get

matlab not displaying an approximated value of an improper integral? (27)

Now we will apply your idea of approximation in the vicinity of 0 for the two integrals via matlab, we find:

matlab not displaying an approximated value of an improper integral? (28)

Nathan Hardenberg on 25 Aug 2023

Direct link to this comment

https://support.mathworks.com/matlabcentral/answers/2011812-matlab-not-displaying-an-approximated-value-of-an-improper-integral#comment_2861122

  • Link

    Direct link to this comment

    https://support.mathworks.com/matlabcentral/answers/2011812-matlab-not-displaying-an-approximated-value-of-an-improper-integral#comment_2861122

@Lahcen Glad I I could help. Nice idea to use the better numerical precision near 0 to get a better approximation

Now I also got interested in the convergance 😀 I did not find the formula by Bertrand you provided. I only found the following. Always converging when matlab not displaying an approximated value of an improper integral? (30)

But this is obiously somthing else, regarding the area after matlab not displaying an approximated value of an improper integral? (33) to infinity. Would be greatly appreciated if you would provide a resource, if you can. But no worries if you can't

Lahcen on 25 Aug 2023

Direct link to this comment

https://support.mathworks.com/matlabcentral/answers/2011812-matlab-not-displaying-an-approximated-value-of-an-improper-integral#comment_2861357

  • Link

    Direct link to this comment

    https://support.mathworks.com/matlabcentral/answers/2011812-matlab-not-displaying-an-approximated-value-of-an-improper-integral#comment_2861357

Edited: Lahcen on 26 Aug 2023

Hello Dear @Nathan Hardenberg

Attached you will find a reference about A, concerning your question, (but they are references in French).

But using what you found like, one can find what my published. Indeed, Let a<1 and let putmatlab not displaying an approximated value of an improper integral? (35)

by setting matlab not displaying an approximated value of an improper integral? (36) we find,

matlab not displaying an approximated value of an improper integral? (37)

thenmatlab not displaying an approximated value of an improper integral? (38)

Now, this integral is converge if and only if matlab not displaying an approximated value of an improper integral? (39)

which is equivalent matlab not displaying an approximated value of an improper integral? (40).

I hope you like the proof.

Nathan Hardenberg on 27 Aug 2023

Direct link to this comment

https://support.mathworks.com/matlabcentral/answers/2011812-matlab-not-displaying-an-approximated-value-of-an-improper-integral#comment_2862757

  • Link

    Direct link to this comment

    https://support.mathworks.com/matlabcentral/answers/2011812-matlab-not-displaying-an-approximated-value-of-an-improper-integral#comment_2862757

@Lahcen Thanks a lot :D

Sign in to comment.

More Answers (0)

Sign in to answer this question.

See Also

Categories

MATLABLanguage FundamentalsLoops and Conditional Statements

Find more on Loops and Conditional Statements in Help Center and File Exchange

Tags

  • improper
  • integral

Community Treasure Hunt

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

Start Hunting!

An Error Occurred

Unable to complete the action because of changes made to the page. Reload the page to see its updated state.


matlab not displaying an approximated value of an improper integral? (42)

Select a Web Site

Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .

You can also select a web site from the following list

Americas

  • América Latina (Español)
  • Canada (English)
  • United States (English)

Europe

  • Belgium (English)
  • Denmark (English)
  • Deutschland (Deutsch)
  • España (Español)
  • Finland (English)
  • France (Français)
  • Ireland (English)
  • Italia (Italiano)
  • Luxembourg (English)
  • Netherlands (English)
  • Norway (English)
  • Österreich (Deutsch)
  • Portugal (English)
  • Sweden (English)
  • Switzerland
    • Deutsch
    • English
    • Français
  • United Kingdom(English)

Asia Pacific

  • Australia (English)
  • India (English)
  • New Zealand (English)
  • 中国
  • 日本Japanese (日本語)
  • 한국Korean (한국어)

Contact your local office

matlab not displaying an approximated value of an improper integral? (2024)

FAQs

Why does sin pi not work in Matlab? ›

It is because pi value cannot be represented in floating-point number. One approach to go around it is to use symbolic toolbox: sin(sym(pi)) returns 0. Note that sym(pi) is the exact pi. There is another way without using symbolic toolbox.

How to plot integral equation in matlab? ›

Like so:
  1. K= @(t) (sin(t)-t.*cos(t)).*sin(t);
  2. P = 0:0.1:3.1416;
  3. for i = 1:numel(P)
  4. V(i) = integral(K,0,P(i));
  5. end.
  6. plot(P,V),grid.
Mar 3, 2022

How do you show sin in matlab? ›

Y = sin( X ) returns the sine of the elements of X . The sin function operates element-wise on arrays. The function accepts both real and complex inputs. For real values of X , sin(X) returns real values in the interval [-1, 1].

How to write sin pi in matlab? ›

Y = sinpi( X ) computes sin(X*pi) without explicitly computing X*pi . This calculation is more accurate than sin(X*pi) because the floating-point value of pi is an approximation of π. In particular: For integers, sinpi(n) is exactly zero.

Top Articles
Air Fryer Garlic Bread - Air Fryer Recipes
Refrigerator Pickled Beets; Grandma's Pickled Beets Recipe – Health Starts in the Kitchen
St Thomas Usvi Craigslist
Hotels
The UPS Store | Ship & Print Here > 400 West Broadway
Le Blanc Los Cabos - Los Cabos – Le Blanc Spa Resort Adults-Only All Inclusive
Nc Maxpreps
Erskine Plus Portal
Mawal Gameroom Download
Paula Deen Italian Cream Cake
The Haunted Drury Hotels of San Antonio’s Riverwalk
WK Kellogg Co (KLG) Dividends
Missing 2023 Showtimes Near Lucas Cinemas Albertville
Persona 4 Golden Taotie Fusion Calculator
MindWare : Customer Reviews : Hocus Pocus Magic Show Kit
Christina Khalil Forum
Eva Mastromatteo Erie Pa
Beryl forecast to become an 'extremely dangerous' Category 4 hurricane
Music Go Round Music Store
Theater X Orange Heights Florida
The Tower and Major Arcana Tarot Combinations: What They Mean - Eclectic Witchcraft
Inkwell, pen rests and nib boxes made of pewter, glass and porcelain.
Apparent assassination attempt | Suspect never had Trump in sight, did not get off shot: Officials
Lbrands Login Aces
Rainfall Map Oklahoma
Calvin Coolidge: Life in Brief | Miller Center
100 Million Naira In Dollars
What Is The Lineup For Nascar Race Today
The value of R in SI units is _____?
Mobile Maher Terminal
UPS Drop Off Location Finder
Shiftwizard Login Johnston
Truis Bank Near Me
Garrison Blacksmith's Bench
Police Academy Butler Tech
Craigslist Boats Eugene Oregon
Is Arnold Swansinger Married
Devon Lannigan Obituary
Busted Newspaper Mcpherson Kansas
Woody Folsom Overflow Inventory
Brown launches digital hub to expand community, career exploration for students, alumni
Marcal Paper Products - Nassau Paper Company Ltd. -
Nearest Wintrust Bank
Automatic Vehicle Accident Detection and Messageing System – IJERT
Causeway Gomovies
Www Ventusky
Mkvcinemas Movies Free Download
Optimal Perks Rs3
Grace Charis Shagmag
Lsreg Att
Syrie Funeral Home Obituary
Latest Posts
Article information

Author: Van Hayes

Last Updated:

Views: 5651

Rating: 4.6 / 5 (66 voted)

Reviews: 81% of readers found this page helpful

Author information

Name: Van Hayes

Birthday: 1994-06-07

Address: 2004 Kling Rapid, New Destiny, MT 64658-2367

Phone: +512425013758

Job: National Farming Director

Hobby: Reading, Polo, Genealogy, amateur radio, Scouting, Stand-up comedy, Cryptography

Introduction: My name is Van Hayes, I am a thankful, friendly, smiling, calm, powerful, fine, enthusiastic person who loves writing and wants to share my knowledge and understanding with you.