Facing problem while solving this.
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
AVINASH SAHU
el 31 de Jul. de 2022
Comentada: Walter Roberson
el 31 de Jul. de 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
0 comentarios
Respuesta aceptada
Walter Roberson
el 31 de Jul. de 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.
2 comentarios
Walter Roberson
el 31 de Jul. de 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.
Más respuestas (0)
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!