Facing problem while solving this.

2 views (last 30 days)
AVINASH SAHU on 31 Jul 2022
Commented: Walter Roberson on 31 Jul 2022
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 on 31 Jul 2022
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.
AVINASH SAHU on 31 Jul 2022
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 on 31 Jul 2022
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.