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!