Error when calling parameterized function

1 次查看(过去 30 天)
Here is my main body code:
d = .0127;
a = .00635;
x = d/a;
val = scalingfunction(x)
Here is my function code:
function [val] = scalingfunction(x)
fun = @(x,y) ((1/(y^2+1)^(3/2))-(1/((y+x)^2 + 1))^(3/2))^2;
val = integral(@(y) fun(x,y),-Inf,Inf);
end
Here is my error:
val = integral(@(y) fun(x,y),-Inf,Inf);
Error in electro_magnetic_model (line 4)
val = scalingfunction(x);

采纳的回答

Star Strider
Star Strider 2020-3-24
Use element-wise operations:
function [val] = scalingfunction(x)
fun = @(x,y) ((1./(y.^2+1).^(3/2))-(1./((y+x).^2 + 1)).^(3/2)).^2;
val = integral(@(y) fun(x,y),-Inf,Inf);
end
that then produces:
val =
1.700680101619312
See Array vs. Matrix Operations for a detailed description.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Quantum Mechanics 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by