loop calculation and skipping the numbers
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
YOGESHWARI PATEL
el 6 de Dic. de 2021
Comentada: Star Strider
el 8 de Dic. de 2021
d=20;
h=2;
g=9.8;
u=zeros(1)
v=zeros(1)
for x=[1 6 11 16 21 ]
for t=[1 6 11 16 21 26 31]
u(x,t)=h*sqrt(g/d)*(sech((sqrt(3*h/4*d^3))*(((x-1)/10)-(sqrt(g/d)*(1+(h/2*d))*((t-1)/10)))))^2;
v(x,t)=h*(sech((sqrt(3*h/4*d^3))*((x-1/10)-(sqrt(g/d)*(1+(h/2*d))*(t-1/10)))))^2;
end
end
disp(u)
disp(v)
I use this code to evaluate the value of u and v at different x and t .I want to skip the values so i wish this code .But all the values are not displayed.
0 comentarios
Respuesta aceptada
Star Strider
el 6 de Dic. de 2021
The indexing is incorrect. It leaves gaps. The gaps can be eliminated with a more efficient indexing approach.
This fixes that problem, however other problems may remain.
d=20;
h=2;
g=9.8;
% u=zeros(1)
% v=zeros(1)
xv=[1 6 11 16 21 ];
tv=[1 6 11 16 21 26 31];
u = NaN(numel(xv), numel(tv));
v = NaN(numel(xv), numel(tv));
for k1 = 1:numel(xv)
x = xv(k1);
for k2 = 1:numel(tv)
t = tv(k2);
u(k1,k2)=h*sqrt(g/d)*(sech((sqrt(3*h/4*d^3))*(((x-1)/10)-(sqrt(g/d)*(1+(h/2*d))*((t-1)/10)))))^2;
v(k1,k2)=h*(sech((sqrt(3*h/4*d^3))*((x-1/10)-(sqrt(g/d)*(1+(h/2*d))*(t-1/10)))))^2;
end
end
disp(u)
disp(v)
.
2 comentarios
Star Strider
el 8 de Dic. de 2021
Preallocating the matrices, then referencing the variables as elements of the original variable vectors.
Más respuestas (0)
Ver también
Categorías
Más información sobre Loops and Conditional Statements 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!