Error while performing integration

1 Ansicht (letzte 30 Tage)
Muhammad Mubashar saeed
Muhammad Mubashar saeed am 24 Apr. 2021
Beantwortet: David Hill am 24 Apr. 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

Akzeptierte Antwort

Alan Stevens
Alan Stevens am 24 Apr. 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

Weitere Antworten (1)

David Hill
David Hill am 24 Apr. 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

Kategorien

Mehr zu Startup and Shutdown finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by