Help Plotting a Function
Informazioni
Questa domanda è chiusa. Riaprila per modificarla o per rispondere.
Mostra commenti meno recenti
I have this code that calculates the power in the ocean. function [ ] = OceanPower( d ) %OceanPower uses the depth and calculates the wave power in W/m
A=1.042;%amplitude
T=8.75;%Period
rho=1025;%Density
g=9.81;
if d <= 0.05^2*g*T^2 %calculates wavelength if in shallow waters
L=T*sqrt(g*d)
elseif (d>0.05^2*g*T^2) &&(d<g*T^2/(4*pi))%numerically caluclates L for transitional depth
Li=200;
L=(g*T^2/2*pi)*tanh(2*pi*d/Li);
while abs(L-Li) > 0.02
Li=L;
L=(g*T^2/2*pi)*tanh(2*pi*d/Li)
end
else d >= g*T^2/(4*pi)%calculates wavelength if in deep waters
L=g*T^2/(2*pi)
end
[P]=(rho*g*(A^2)*sqrt((g*L)/(2*pi)))/4;
disp(P)
end
if true
% code
end
Depending the value of d changes what equation it uses. I would like to see this function in a plot vs. the depth.
Risposte (1)
Star Strider
il 4 Ott 2018
I have no idea what you want. I assume you want a plot of ‘P’ as a function of ‘d’.
If so, try this:
dv = linspace(0.001, 10, 150);
for k1 = 1:numel(dv)
d = dv(k1);
A=1.042;%amplitude
T=8.75;%Period
rho=1025;%Density
g=9.81;
if d <= 0.05^2*g*T^2 %calculates wavelength if in shallow waters
L=T*sqrt(g*d);
elseif (d>0.05^2*g*T^2) &&(d<g*T^2/(4*pi))%numerically caluclates L for transitional depth
Li=200;
L=(g*T^2/2*pi)*tanh(2*pi*d/Li);
while abs(L-Li) > 0.02
Li=L;
L=(g*T^2/2*pi)*tanh(2*pi*d/Li);
end
else d >= g*T^2/(4*pi)%calculates wavelength if in deep waters
L=g*T^2/(2*pi);
end
P(k1) = (rho*g*(A^2)*sqrt((g*L)/(2*pi)))/4;
% disp(P)
end
figure
plot(dv, P)
grid
xlabel('d')
ylabel('P')
Experiment to get the result you want.
Questa domanda è chiusa.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!