フィルターのクリア

Facing problem while solving this.

1 回表示 (過去 30 日間)
AVINASH SAHU
AVINASH SAHU 2022 年 7 月 31 日
コメント済み: Walter Roberson 2022 年 7 月 31 日
p1 = @(x) (1./F(x)) .* ((0.5 .* hbar(x)) - Q);
P = @(x) integral(@(x) p1(x),0,x,'ArrayValued', true);
xi = linspace(0,1) ;
P1 = zeros(size(xi)) ;
for j = 1:length(xi)
P1(j) = P(xi(j));
end
Using the abpve approach I am getting datasets of P1 but not able to figure out how to approach in the following method given below
for i = 1:100
p1(i) =(((0.5*hbar(i))-Q)/F(i));
% P = @(x) integral(@(x) p1(x),0,x,'ArrayValued', true); %%%% how
% to write this line here?
end

採用された回答

Walter Roberson
Walter Roberson 2022 年 7 月 31 日
p1{1} = @(x) (1./F(x)) .* ((0.5 .* hbar(x)) - Q);
P{1} = @(x) integral(p1{1}, 0, x, 'ArrayValued', true);
xi = linspace(0,1) ;
P1 = zeros(size(xi)) ;
for j = 1:length(xi)
P1(j) = P{1}(xi(j));
end
for i = 1:100
p1{i} = @(x) (((0.5*hbar(i))-Q)/F(i));
P{i} = @(x) integral(p1{i}, 0, x, 'ArrayValued', true);
end
Note that this would overwrite the original p1{1} and P{1}
Also note that your p1{i} does not involve x, so the body would effectively be constant, and the result of the integral would be x times the constant minus 0 times the constant, which is predictable ahead of time.
  2 件のコメント
AVINASH SAHU
AVINASH SAHU 2022 年 7 月 31 日
Appreciating your help. But I want to say that I am getting the results (i.e. datasets of P1) using the following approach
p1 = @(x) (1./F(x)) .* ((0.5 .* hbar(x)) - Q);
P = @(x) integral(@(x) p1(x),0,x,'ArrayValued', true);
xi = linspace(0,1) ;
P1 = zeros(size(xi)) ;
for j = 1:length(xi)
P1(j) = P(xi(j));
end
and I want to get the same results using the below approach but don't know how to proceed
p1(i) =(((0.5*hbar(i))-Q)/F(i)); % same as above p1
% P = ?????
% P = @(x) integral(@(x) p1(x),0,x,'ArrayValued', true); %%%% how
% to write this line here in the form of indices and the obtain the
% datasets of uppercase "P1"
xi = linspace(0,1) ;
P1 = zeros(size(xi)) ;
for j = 1:length(xi)
P1(j) = P(xi(j));
end
Thank you very much for your help. Hope I am able to clarify my problem.
Walter Roberson
Walter Roberson 2022 年 7 月 31 日
You cannot do that.
Your original code defines p1 as an anonymous function handle. Your new version defines p1(i) as a numeric constant, not as a function handle. It is not useful to integrate a numeric constant.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by