Error while performing integration
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Muhammad Mubashar saeed
el 24 de Abr. de 2021
Respondida: David Hill
el 24 de Abr. de 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 comentarios
Respuesta aceptada
Alan Stevens
el 24 de Abr. de 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 comentarios
Más respuestas (1)
David Hill
el 24 de Abr. de 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 comentarios
Ver también
Categorías
Más información sobre Startup and Shutdown en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!