Can someone help me with this integration
4 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Ali Almakhmari
am 4 Mär. 2022
Bearbeitet: Walter Roberson
am 4 Mär. 2022
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 Kommentare
Akzeptierte Antwort
Torsten
am 4 Mär. 2022
Bearbeitet: Torsten
am 4 Mär. 2022
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 Kommentar
Weitere Antworten (1)
AndresVar
am 4 Mär. 2022
Bearbeitet: AndresVar
am 4 Mär. 2022
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 Kommentare
Siehe auch
Kategorien
Mehr zu Calculus finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!