loop calculation and skipping the numbers
3 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
YOGESHWARI PATEL
il 6 Dic 2021
Commentato: Star Strider
il 8 Dic 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 Commenti
Risposta accettata
Star Strider
il 6 Dic 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 Commenti
Star Strider
il 8 Dic 2021
Preallocating the matrices, then referencing the variables as elements of the original variable vectors.
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Loops and Conditional Statements in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!