Facing problem while solving this.

1 次查看(过去 30 天)
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 中查找有关 MATLAB 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by