# Write a loop to plot a model graph

3 views (last 30 days)
Anitha Limann on 21 Oct 2021
Commented: Anitha Limann on 21 Oct 2021
Hello,
I wrote this code build a model to find the velocities.
The observed data are plotted in blue and model is in red asteric marks. The model graph also should be a curve that lies closer to observed data with the same shape, however for some reason i get a staright line for this.
Could someone please check this one out and help me figure out my mistake.
I have attached the graph of VL vs T. and instructions i used to write this code.  %% Observed Wave dispersion data;
Tob = (10:5:90); % s (time)
VLob = [3.6 3.7 3.9 4.0 4.2 4.3 4.4 4.45 4.5 4.6 4.65 4.7 4.75 4.8 4.82 4.85 4.9]; %km/s (observed velocities)
figure (2);
plot(Tob,VLob,'b+') %observed graph
hold on;
grid
%%
T=10; % s
Tmax = 90; %s
VL = 3.61; %km
vs1=3.6;
vs2=4.7;
d1=2.9;
d2=3.2;
z=40;
dt=5;
dv=0.05: % used instead of 0.005 of condition "VL = VL+0.005"
for T=T:dt:Tmax
A = atan((vs2^2)*D2*(sqrt(1-(VL^2/vs2^2)))/(vs1^2)*D1*(sqrt((VL^2/vs1^2)-1)));
B = (((2*pi*z)/(VL*T))*(sqrt((VL^2/vs1^2)-1)));
if abs(A-B)<0.001
figure (2)
plot(T,VL,'r*')
hold on;
break
else
VL=VL+dv;
figure (2)
plot(T,VL,'r*')
end
end

Alan Stevens on 21 Oct 2021
Edited: Alan Stevens on 21 Oct 2021
A little more like this. You need a smaller value of dv and a while loop. The fit isn't very good!
%% Observed Wave dispersion data;
Tob = (10:5:90); % s (time)
VLob = [3.6 3.7 3.9 4.0 4.2 4.3 4.4 4.45 4.5 4.6 4.65 4.7 4.75 4.8 4.82 4.85 4.9]; %km/s (observed velocities)
figure (2);
plot(Tob,VLob,'b+') %observed graph
hold on;
grid
%%
T0=10; % s
Tmax = 90; %s
VL = 3.61; %km
vs1=3.6;
vs2=4.7;
d1=2.9;
d2=3.2;
z=40;
dt=5;
dv=0.0005; % used instead of 0.005 of condition VL = VL+0.005
itmax = 1000;
for T=T0:dt:Tmax
its = 0;
delta = 1;
while delta>0.001 && its<itmax
A = atan(vs2^2*d2*sqrt(1-VL^2/vs2^2)/(vs1^2*d1*sqrt(VL^2/vs1^2-1)));
B = 2*pi*z/(VL*T)*sqrt(VL^2/vs1^2-1);
VL = VL+dv;
its = its+1;
delta = abs(A-B);
end
plot(T,VL,'r*')
end Anitha Limann on 21 Oct 2021
Hello,
Thank you so much. That does make sence for why i would only get the expected graph for rounded off values.
This helps a lot.
Dilini