To find integral of a function in loop

2 ビュー (過去 30 日間)
Nadia jabeen
Nadia jabeen 2021 年 7 月 6 日
コメント済み: Alan Stevens 2021 年 7 月 6 日
Hi,
I am calculating integral of a function 'f' with respect to lamda. I want to calculate variable 'q' for all possible values given in range of variable 'x'. upper limit and lower limit of variable lamda is as same as in variable 'x'. But matlab function given an error. kingly ghide me. or matlab show output of a single value. I want to do these calculations as a vector.
x = [600*10^-9:5*10^-9:800*10^-9];
for i = 1:numel(x)
N=(15.*z.*T*((h.*c).^3));
f=@(lamda)((Pi.^4).*(lamda.^4)*(k.^3));
q = integral(f,6e-7, x);
F=(N./q);
end

採用された回答

Alan Stevens
Alan Stevens 2021 年 7 月 6 日
Try replacing
q = integral(f,6e-7, x);
with
q(i) = integral(f,6e-7, x(i));
  2 件のコメント
Nadia jabeen
Nadia jabeen 2021 年 7 月 6 日
Now error has been removed. But only one value is appear for q(i). I want to plot a graph for all values of q(i). how can I store all these values in one variable?
Alan Stevens
Alan Stevens 2021 年 7 月 6 日
q holds all the results! For example:
x = [600*10^-9:5*10^-9:800*10^-9];
% Arbitrary data - replace with your own
N=1; %(15.*z.*T*((h.*c).^3));
k = 10^3;
lambda = 10^4;
f=@(lamda)((pi.^4).*(lamda.^4)*(k.^3));
for i = 1:numel(x)
q(i) = integral(f,6e-7, x(i));
F=(N./q);
end
plot(x,q),grid
xlabel('x'),ylabel('q')

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeGlobal or Multiple Starting Point Search についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by