Integration containing multiple variable and plotting

11 ビュー (過去 30 日間)
Supriya Khatoniar
Supriya Khatoniar 2022 年 4 月 24 日
コメント済み: Star Strider 2022 年 4 月 25 日
Can anybody help me to integrate & plot in the following format, i.e. contains multiple variables?:
z = 0:0.1:10;
a = -0.5:0.1:1;
x = 0:0.1:2;
y = 2*exp(-0.5*z) + x;
I = 0.2 ∫(0.5*(a-y)+0.3) dx
integration limit : 0 to x
plot (I,x);
  10 件のコメント
Star Strider
Star Strider 2022 年 4 月 24 日
Also, How do you check a function's efficiency? Just checking it's time to run a sample of code?
That is how I usually do it. The timeit approach is most accurate, however I usually just use tic and toc. and occasionally the profile function, depending on the information I am interested in.
Supriya Khatoniar
Supriya Khatoniar 2022 年 4 月 25 日
@Dyuman Joshi @Star Strider @Torsten glad to see your fruitfull discussion. Thanks, I'll go through it. I wish to apply this kind of logic in some other codes & if I face some problem, I'll ask.

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

採用された回答

Star Strider
Star Strider 2022 年 4 月 24 日
To use vectors as arguments in the integrand, it is necessary to use integral and the 'ArrayValued',true name-value pair —
% z = 0:0.1:10;
% a = -0.5:0.1:1;
% x = 0:0.1:2;
N = 5; % Determines The Lengths Of The Vectors
z = linspace(0, 10, N);
a = linspace(-0.5, 1, N);
x = linspace(0, 2, N);
y = @(x) 2*exp(-0.5*z) + x;
I = arrayfun(@(x) 0.2 * integral(@(x) 0.5*(a-y(x))+0.3, 0, x, 'ArrayValued',1), x, 'Unif',0)';
Im = cell2mat(I);
figure
plot(x, Im)
legend(compose('x = %.2f',x), 'Location','best')
.
  2 件のコメント
Supriya Khatoniar
Supriya Khatoniar 2022 年 4 月 25 日
Helpful.
Star Strider
Star Strider 2022 年 4 月 25 日
Thank you!

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

その他の回答 (1 件)

Sulaymon Eshkabilov
Sulaymon Eshkabilov 2022 年 4 月 24 日
Use integral3: https://www.mathworks.com/help/matlab/ref/integral3.html
  1 件のコメント
Supriya Khatoniar
Supriya Khatoniar 2022 年 4 月 24 日
編集済み: Supriya Khatoniar 2022 年 4 月 24 日
@Sulaymon Eshkabilov Okay, can I apply tripple integral in this case?

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

カテゴリ

Help Center および File ExchangeNumerical Integration and Differentiation についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by