How to plot graphic with 2 variables function
10 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos

I use these codes:
clear
clc
H=2.5
h=11
T=9
w=2*pi/T
k1=1
g=9.81
%This is Newton's Rhapson Method
x1=k1*h;
TOL=1.0e-5;
f=@(x) x*tanh(x)-w^2*h/g;
df=@(x) tanh(x)+(x/(cosh(x))^2);
fprintf ('Iteration root f(root) \n')
if df(x1) ~= 0
for i=1:1000
x2=x1-(f(x1)/df(x1));
fprintf ('ke-%d %.5f %.5f\n', [i,x1,f(x1)]')
if abs (f(x2)) < TOL
break
end
x1=x2;
end
end
fprintf ('root: %f\n',x1')
fprintf ('Number of iteration: %f\n', i')
L=2*pi()*h/x1
% PLOT
kgel=x1/h
xi=-L/4
xf=5*L/4
t=0
fplot(@(x) H/2 * cos(kgel.*x - w*t),[xi xf],'Color','c','LineWidth',1.5)
title('u and w in t=0')
xlabel('x axis')
ylabel('z axis')
grid
nx1=L/4
nx2=3*L/4
nx3=L/2
nx4=L
hold on
fplot(@(z) (H*w/2)*(cosh(kgel*(h+z))/sinh(kgel*h))*cos(kgel*nx1-w*t),[-h H])
fplot(@(z) (H*w/2)*(sinh(kgel*(h+z))/sinh(kgel*h))*sin(kgel*nx1-w*t),[-h H])
hold off
What should i do?
went wrong like this:

7 comentarios
Dyuman Joshi
el 10 de Mzo. de 2023
How did you come to the conclusion that u and v at t=0 are given by
H/2 * cos(kgel.*x - w*t)
The magnitude of u (~10^-16) is quite small compared to v (~1), see the plots at the end. Are the numerical values all correct? I suggest you to cross-check.
H=2.5;
h=11;
T=9;
w=2*pi/T;
k1=1;
g=9.81;
%This is Newton's Rhapson Method
x1=k1*h;
TOL=1.0e-5;
f=@(x) x*tanh(x)-w^2*h/g;
df=@(x) tanh(x)+(x/(cosh(x))^2);
Also, it's not clear what you want to do here with the if condition.
if df(x1) ~= 0
for i=1:1000
x2=x1-(f(x1)/df(x1));
if abs (f(x2)) < TOL
break
end
x1=x2;
end
end
L=2*pi*h/x1;
% PLOT
kgel=x1/h;
xi=-L/4;
xf=5*L/4;
t=0;
fplot(@(x) H/2 * cos(kgel.*x - w*t),[xi xf],'Color','c','LineWidth',1.5)
title('u and w in t=0')
xlabel('x axis')
ylabel('z axis')
grid
nx1=L/4;
nx2=3*L/4;
nx3=L/2;
nx4=L;
%x-velocity
u = @(z) (H*w/2)*(cosh(kgel*(h+z))/sinh(kgel*h))*cos(kgel*nx1-w*t);
%y-velocity
v = @(z) (H*w/2)*(sinh(kgel*(h+z))/sinh(kgel*h))*sin(kgel*nx1-w*t);
figure
fplot(u,[-h H])
figure
fplot(v,[-h H])
Respuestas (0)
Ver también
Categorías
Más información sobre 2-D and 3-D Plots en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


