Can someone help me with this integration
4 次查看(过去 30 天)
显示 更早的评论
In addition to getting an error in this, what I want to essentially do is replace f1(1, i) in the integ2 variable, but I keep getting f1(1, i) as it is. Its like I am telling MATLAB to evaluate f1(1,i) with the actual f1(1,i) from the Workspace but its just leaving it as it is.
clear
clc
beep off
theta_s = 0:0.1:pi/2;
syms theta_v phi
f1 = ((((1/(2.*pi)).*((pi-phi).*cos(phi) + sin(phi)).*tan(theta_s).*tan(theta_v)) - (1/pi).*(tan(theta_s)+tan(theta_v)+sqrt(tan(theta_v).^2 + tan(theta_s).^2 - 2.*tan(theta_s).*tan(theta_v).*cos(phi)))));
for i = 1:length(theta_s)
integ2 = @(theta_v, phi) f1(1,i).*cos(theta_v).*sin(theta_v);
r2(i)= integral2(integ2, 0, pi/2, 0, pi);
end
0 个评论
采纳的回答
Torsten
2022-3-4
编辑:Torsten
2022-3-4
THETA_S = 0:0.1:pi/2;
for i = 1:length(THETA_S)
theta_s = THETA_S(i);
f1 = @(theta_v,phi) ((((1/(2.*pi)).*((pi-phi).*cos(phi) + sin(phi)).*tan(theta_s).*tan(theta_v)) - (1/pi).*(tan(theta_s)+tan(theta_v)+sqrt(tan(theta_v).^2 + tan(theta_s).^2 - 2.*tan(theta_s).*tan(theta_v).*cos(phi)))));
integ2 = @(theta_v, phi) f1(theta_v,phi).*cos(theta_v).*sin(theta_v);
r2(i)= integral2(integ2, 0, pi/2, 0, pi);
end
更多回答(1 个)
AndresVar
2022-3-4
编辑:AndresVar
2022-3-4
you can do it without symbolic variables
clear
theta_s_vec = 0:0.1:pi/2;
for ii = 1:numel(theta_s_vec)
theta_s = theta_s_vec(ii);
integ2 = @(phi,theta_v) cos(theta_v).*sin(theta_v).*((((1/(2.*pi)).*((pi-phi).*cos(phi) + sin(phi)).*tan(theta_s).*tan(theta_v)) - (1/pi).*(tan(theta_s)+tan(theta_v)+sqrt(tan(theta_v).^2 + tan(theta_s).^2 - 2.*tan(theta_s).*tan(theta_v).*cos(phi)))));
r2(ii) = integral2(integ2,0,pi,0,pi/2);
end
r2
r2 = 1×16
-1.5708 -1.5728 -1.5788 -1.5893 -1.6048 -1.6265 -1.6559 -1.6956 -1.7494 -1.8238 -1.9300 -2.0887 -2.3439 -2.8051 -3.8411 -7.9164
You can try symbolically and approximate, you get the same result. But can be slower sometimes.
clear
theta_s = 0:0.1:pi/2;
syms theta_v phi real positive
f1 = ((((1/(2.*pi)).*((pi-phi).*cos(phi) + sin(phi)).*tan(theta_s).*tan(theta_v)) - (1/pi).*(tan(theta_s)+tan(theta_v)+sqrt(tan(theta_v).^2 + tan(theta_s).^2 - 2.*tan(theta_s).*tan(theta_v).*cos(phi)))));
integ2 = f1*cos(theta_v)*sin(theta_v);
for ii = 1:numel(theta_s)
r2(ii)=int(int(integ2(ii),phi,[0 pi]),theta_v,[0 pi/2]);
end
vpa(r2,5)
ans =
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!