Error while performing integration
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Muhammad Mubashar saeed
le 24 Avr 2021
Réponse apportée : David Hill
le 24 Avr 2021
I am getting error while running this code
function Q = Zdirection(y)
alpha=30*pi/180;
beta=120*pi/180;
x=1:0.1:5;
z=3;
a=5;
Q1=pi/180*sqrt((a^2-x^2-y.^2).*( ( z*sin(beta).*sin(alpha) - y.*cos(alpha) ).^2+( cos(alpha)*x - cos(beta)*sin(alpha) *z) .^2));
if Q1>=pi/2
Q1= rem(Q1,pi/2);
end
if Q1<=-pi/2
Q1= rem(Q1,-pi/2);
end
Q = (Q1);
end
x=1:0.1:5;
a=5;
for i=1:length(x)
z(i)=sqrt(a^2-x(i).^2);
Q2(i)=quad(@Zdirection,0,z(i));
Q2(i)=abs(Q2(i));
end
plot(x,Q2,'Linewidth',2);grid on;shg
I am getting error while running this code
0 commentaires
Réponse acceptée
Alan Stevens
le 24 Avr 2021
Like this:
x=1:0.1:5;
a=5;
for i=1:length(x)
z(i)=sqrt(a^2-x(i).^2);
Q2(i)=quad(@(y) Zdirection(y,x(i),a),0,z(i)); %%%%%%%%%%%%%%%
Q2(i)=abs(Q2(i));
end
plot(x,Q2,'Linewidth',2);grid on;shg
function Q = Zdirection(y,x,a) %%%%%%%%%%%%%%%%%%%%
alpha=30*pi/180;
beta=120*pi/180;
z=3;
Q1=pi/180*sqrt((a^2-x.^2-y.^2).*( ( z*sin(beta).*sin(alpha) - y.*cos(alpha) ).^2+( cos(alpha)*x - cos(beta)*sin(alpha) *z) .^2));
if Q1>=pi/2
Q1= rem(Q1,pi/2);
end
if Q1<=-pi/2
Q1= rem(Q1,-pi/2);
end
Q = (Q1);
end
0 commentaires
Plus de réponses (1)
David Hill
le 24 Avr 2021
Or don't even have a Zdirection function
x=1:0.1:5;
a=5;
alpha=30*pi/180;
beta=120*pi/180;
Z=3;
for i=1:length(x)
z(i)=sqrt(a^2-x(i).^2);
Q1=quad(@(y)pi/180*sqrt((a^2-x(i)^2-y.^2).*( ( Z*sin(beta).*sin(alpha) - y.*cos(alpha) ).^2...
+( cos(alpha)*x(i) - cos(beta)*sin(alpha) *Z) .^2)),0,z(i));
if Q1>=pi/2
Q1= rem(Q1,pi/2);
elseif Q1<=-pi/2
Q1= rem(Q1,-pi/2);
end
Q2(i)=abs(Q1);
end
plot(x,Q2,'Linewidth',2);grid on;shg
0 commentaires
Voir également
Catégories
En savoir plus sur Startup and Shutdown dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!