# Chapter10

%problem 6
x = -2:0.2:2;
y = -2:0.2:2;
figure(6)
[X,Y] = meshgrid(x,y);
z = (-1.4.*X.*(Y.^3))+(1.4.*Y.*(X.^3));
surf(X,Y,z)
title('Surface plot z=-1.4xy^3 + 1.4yx^3')
xlabel('x','fontsize',18);
ylabel('y','fontsize',18);
zlabel('z','fontsize',18);

%problem 7
x = -5:0.1:5;
y = -5:0.1:5;
figure(7)
[X,Y] = meshgrid(x,y);
R = sqrt(X.^2+Y.^2);
Z = -cos(2*R)./exp(0.2*R);
mesh(X,Y,Z)
xlabel('x'); ylabel('y'); zlabel('z')

%problem 8
x = -pi:0.1:pi;
y = -pi:0.1:pi;
figure(8)
[X,Y] = meshgrid(x,y);
Z = cos(0.7*X+0.7*Y).*cos(0.7*X-0.7*Y);
surf(X,Y,Z)
%can chan the calor of the picture with "colormap Winter"
xlabel('x'); ylabel('y'); zlabel('z')

%problem 9
r = 0:0.2:2;
theta = 0:pi/15:2*pi;
figure(9)
[R,THETA] = meshgrid(r,theta);
X = R.*cos(THETA);
Y = R.*sin(THETA);
Z = 4*R;
mesh(X,Y,Z)
clear
theta = 0:pi/15:2*pi;
phi = 0:pi/16:pi;
hold on
[THETA, PHI] = meshgrid(theta, phi);
mesh(X,Y,Z)
hold off

%problem 10
x = -20:.5:20;
y = 2:.5:10;
[X,Y] = meshgrid(x,y);
alpha = pi.*(Y).*sind(X);
I = (sin(alpha)./alpha).^2;
figure(10)
mesh(X,Y,I)
grid on
xlabel('\theta (deg)')
ylabel('\alpha/\lambda')
zlabel('Relative Intensity')
view(210,30)

%problem 11
R=8.31; M=0.032;
x=linspace(0,1000,28);
y=linspace(70,320,16);

[X,Y]=meshgrid(x,y);
Z=4*pi*(M./(2*pi*R*Y)).^(3/2).*X.^2.*exp(-M*X.^2./(2*R*Y));
figure(1)
mesh(X,Y,Z)
xlabel('\fontsize{14}Molecules Speed (m/s)')
ylabel('\fontsize{14}Temperature (K)')
zlabel('\fontsize{14}Probability')

%problem 12
C1=3.742E8; C2=1.439E4;
L=0.1:0.2:10;
T=100:100:2000;
[W,D]=meshgrid(L,T);
LL=log10(W);
E=C1./(W.^5.*(exp(C2./(W.*D)-1)));
figure
%surf(X,Y,Z)
figure(2)
mesh(W,D,E,'EdgeColor','k')
set(gca,'xscale','log')
xlabel('Wavelength (\mum)'); ylabel('Temperature (K)');
zlabel('Emissive Power (W/m^2\mum)')

%problem 13
r = 0:0.5:2;
d = 0.05:0.2:0.5;
[X,Y] = meshgrid(r,d);
Z = 1./sqrt((1-X.^2).^2+(2*Y.*X).^2);
figure(3)
mesh(X,Y,Z);
xlabel('Damping Ration')
ylabel('Normalized Amplitud')
zlabel('Frequency Ratio')

%problem 14
Em=24; L=240e-3; C=15e-6;
w0=1/sqrt(L*C);
f=linspace(60,110,40);
r=linspace(10,40,20);
[F,R]=meshgrid(f,r);
I=Em./sqrt(R.^2+(2*pi*F*L-1./(2*pi*F*C)).^2);
figure(4)
mesh(F,R,I)
colormap([0 0 0])
xlabel('Frequency (Hz)')
ylabel('Resistance (\Omega)')
zlabel('Current (A)')
%part b
Em=24; L=240e-3; C=15e-6;
f=linspace(60,110,40);
r=linspace(10,40,20);
[F,R]=meshgrid(f,r);
I=Em./sqrt(R.^2+(2*pi*F*L-1./(2*pi*F*C)).^2);
figure(5)
mesh(F,R,I)
view(0,0)
colormap([0 0 0])
xlabel('Frequency (Hz)')
ylabel('Resistance (\Omega)')
zlabel('Current (A)')
%problem 15
delta = 0:1:90;
R = 0.02:0.001:0.1;

%problem 16

%problem 17
x = -3:0.05:3;
y = -3:0.05:3;
[X,Y ] = meshgrid(x,y);
Z = Y-Y./(X.^2+Y.^2);
figure(6)
contour(X,Y,Z,100,'k')
xlabel('x'); ylabel('y')
zlabel('z')
hold on
th=linspace(0,2*pi,100);
r(1,1:100)=1;
figure(7)
polar(th,r)
axis equal
hold off

%problem 18
p=15; rd=15;
E=10E6; t=0.08; nu=0.3;
K=E*t^3/(12*(1-nu^2));
C=p*rd^4/(64*K);

[th,r] = meshgrid((0:5:360)*pi/180,0:1:rd);
[X,Y] = pol2cart(th,r);
%R = sqrt(X.^2 + Y.^2);
w=C*(1-(r/rd).^2).^2;
figure(8)
surf(X,Y,w)
xlabel('x (in.)'); ylabel('y (in.)'); zlabel('w (in.')
%problem 19
r=0.1; N0=10;
t=0:10:100;
Ninf=100:50:1000;
[X,Y]=meshgrid(t,Ninf);
N=Y./(1+(Y/N0-1).*exp(-r*X));
figure(9)
mesh(X,Y,N)
xlabel('t (s)')
ylabel('Ninf')
zlabel('N')
%problem 20
T=0.5; B=1.2;L=4;
x=-2:0.2:2;
z=0:-0.09:-0.45;
[X,Z]=meshgrid(x,z);
Y=B/2*(1-(2*X/L).^2).*(1-(Z/T).^2);

C=[0 0 0];
figure(10)
mesh(X,Y,Z)
xlabel('x'); ylabel('y'); zlabel('z')
axis([-2 2 -1 1 -0.6 0])
hold on
Y=-B/2*(1-(2*X/L).^2).*(1-(Z/T).^2);

mesh(X,Y,Z)
colormap(C)
%problem 21

p=15; rd=3;
E=10E6; t=0.08; nu=0.3;
K=E*t^3/(12*(1-nu^2));
K1=300;
C=p*rd^4/(64*K);

[th,r] = meshgrid((0:5:90)*pi/180,0.02:0.01:0.14);
[X,Y] = pol2cart(th,r);
%R = sqrt(X.^2 + Y.^2);

Sx=K1./sqrt(2*pi*r).*cos(th/2).*(1-sin(th/2).*sin(3*th/2));
Sy=K1./sqrt(2*pi*r).*cos(th/2).*(1+sin(th/2).*sin(3*th/2));
Sxy=K1./sqrt(2*pi*r).*cos(th/2).*sin(th/2).*cos(3*th/2);
figure(11)
mesh(X,Y,Sx)
xlabel('x (in.)'), ylabel('y (in.)'), zlabel('Sx (ksi)')

%problem 22
clear
g=9.81;
V=20; thz=30; thx=25; thy=65;
Vz=V*cosd(thz);
Vx=V*sind(thz)*cosd(thx); Vy=V*sind(thz)*sind(thx);
n=5;
k=11;
X(1)=0; Y(1)=0;
for i=1:5
tb(i)=2*Vz/g;
tbn=linspace(0,tb(i),k);
Zn=Vz*tbn-g*tbn.^2/2;
length(Zn);
Xn=Vx*tbn;
Yn=Vy*tbn;
in=(i-1)*10+1;
jn=in+k-1;
Z(in:jn)=Zn;
X(in:jn)=Xn+X(in);
Y(in:jn)=Yn+Y(in);
Vz=Vz*0.8;
end
figure(12)
plot3(X,Y,Z)
axis([0,120,0,150,0,12])
grid on
xlabel('x (m)'); ylabel('y (m)'); zlabel('z (m)')