MATLAB Answers

Integration numerical with variable limits

77 ビュー (過去 30 日間)
DM
DM 2014 年 10 月 3 日
コメント済み: Vivek Sharma 2021 年 6 月 16 日
I am trying to find a double integration numerically where the inner integral has variable limits while the outer integral has scalar limits and not the other way round. As I understand integral2 allows you do the reverse of what I want i.e you can have the outer variable limits non scalar while the inner should be scalar.
fxy=@(x,y)1/x+1/y
xmin=0;
xmax=@(y)2*y;
ymin=0;
ymax=+inf;
integral2(fxy,xmin,xmax,ymin,ymax)
I get the following error
Error using integral2 (line 76)
XMAX must be a floating point scalar.

採用された回答

Mike Hosea
Mike Hosea 2014 年 10 月 3 日
The INTEGRAL2 interface is set up to calculate an iterated integral where the integral over the second argument of the integrand function f is the inner integral. It does not matter what you call your variables, whether it be x, y, t, p, r, or whatever. The first argument is the outer integral, and the second argument is the inner integral. If your problem happens to be formulated so that the inner integral variable is called x and the outer integral variable is called y, but your integrand is already defined so that x is the first argument and y is the second, then you just do this:
integral2(@(y,x)f(x,y),ymin,ymax,xmin,xmax)
Your example isn't integrable, or I'd demonstrate.
  1 件のコメント
Vivek Sharma
Vivek Sharma 2021 年 6 月 16 日
この コメント は 1 人のコントリビューターによってフラグが設定されました
Dear Sir,
Hope you are fit and sailing the storm perfectly.
I need help in writing a MATLAB code for the problem attached herewith .
I shall be thankful to you.
Best Wishes,
Vivek Sharma

サインインしてコメントする。

その他の回答 (2 件)

Alberto
Alberto 2014 年 10 月 3 日
編集済み: Alberto 2014 年 10 月 3 日
There is a general solution using symbolic tools.
syms x y
fxy=1./x+1./y;
xmin=0;
xmax=2*y;
ymin=0;
ymax=+inf
int(fxy,x,xmin, xmax) % integration dx
int(int(fxy,x,xmin, xmax),y,ymin,ymax) % double integration

Andrei Bobrov
Andrei Bobrov 2014 年 10 月 3 日
in your case:
out = integral2(fxy,ymin,ymax,xmin,xmax);
  2 件のコメント
DM
DM 2014 年 10 月 3 日
What you suggested is performing double integral over dxdy but with the wrong limits since you reversed them @andrei bobrov

サインインしてコメントする。

Community Treasure Hunt

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

Start Hunting!

Translated by