필터 지우기
필터 지우기

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 CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by