Error while performing integration
1 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
Alan Stevens
2021-4-24
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 个评论
更多回答(1 个)
David Hill
2021-4-24
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 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Startup and Shutdown 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!