%PLOTTING ARRIVAL TIMES OF DIRECT, REFLECTED & HEAD WAVE
%DEFINING VARIABLES
h=[2:10]; %Depth
v1=3500:4000; %Velocity
x=[0:40]; %Horizontal Distance
%FORMULAE FOR ARRIVAL TIMES
t_reflect = ((x.^2+4*h.^2).^0.5/v1); %Formula for arrival time
I am making some simple plots of seismic rays, modelling a reflecting rays arrival time against horizontal distance, using the formula in the code.
Initially, the distance is a range of values from 0 - 40m, and the velocity and depth are just set values.
Now, I am trying to plot the arrival time as a function of a range of velocities and as function of a range of depths at a certain point along the x axis (two subplots I suppose)
eg x=10
v1 = [2500:4000]
h = [2:10]
but obviously the matrix dimensions do not agree...any help appreciated

 채택된 답변

Star Strider
Star Strider 2015년 5월 7일

0 개 추천

If they all need to be equal length (it looks like they do), the linspace function can create them.

댓글 수: 7

JDilla
JDilla 2015년 5월 7일
I have looked at the help section, and still don't understand how to implement the linspace function
I have managed to comjure up this
h=5;
v1=3500;
x=linspace(0,10);
v_range=linspace(2500,4000)
but it makes an almost identical graph with the distance/time graph. it should be a velocity/time plot
This is probably the only feasible way I can imagine plotting what is essentially a four-dimensional data set:
h = linspace(2, 10, 5); %Depth
v1 = linspace(3500, 4000, 10);; %Velocity
x = linspace(0, 40, 15); %Horizontal Distance
[H,V1,X] = meshgrid(h, v1, x);
t_reflect = @(h,v1,x) (sqrt(x.^2+4*h.^2)./v1); %Formula for arrival time
T_Reflect = t_reflect(H,V1,X);
figure(1)
M = squeeze(T_Reflect(1,:,:));
plot(x, M)
xlabel('Horizontal Distance')
ylabel('Arrival Time')
hLeg = strsplit(sprintf('%.0f ',h),' ');
legend(hLeg(1:end-1), 'Location','NW')
This particular plot is time as a function of horizontal distance for various depths at a velocity of 3500. Experiment with the various plot options to get them the way you want.
JDilla
JDilla 2015년 5월 7일
편집: JDilla 2015년 5월 7일
Thank you for your effort.
However, I had already solved the problem of plotting time as a function of horizontal distances.
My problem is that I am trying to plot time as a function of velocity = [2500:4000]
and then time as a function of depth = [2:10]
BOTH at the POINT x = 10, as opposed to x=[0:40]
This is where I am having dimension errors.
That information was not in your original Question, nor could I infer it.
That’s a much easier problem:
h = linspace(2, 10, 5); %Depth
v1 = linspace(3500, 4000, 10);; %Velocity
x = linspace(0, 40, 15); %Horizontal Distance
[H,V1] = meshgrid(h, v1);
t_reflect = @(h,v1,x) (sqrt(x.^2+4*h.^2)./v1); %Formula for arrival time
T_Reflect = t_reflect(H,V1,10); % Calculate Time At x=10
figure(1)
surf(H, V1, T_Reflect)
xlabel('Depth')
ylabel('Velocity')
zlabel('Arrival Time')
title('Time as a function of depth and velocity at distance = 10')
The third argument in linspace are the number of points it creates, so if you want a finer grid, simply increase those values. The rest of the code adapts automatically.
Star Strider
Star Strider 2015년 5월 9일
JDilla’s ‘Answer’ moved here...
I rather have it\two seperate plots, one for velocity range, one for depth range. Not a surf plot, how would I do this? it's not really showing the information I want.
Thanks for help
To plot those individually (all at distance = 10):
h = linspace(2, 10, 5); %Depth
v1 = linspace(3500, 4000, 10);; %Velocity
x = linspace(0, 40, 15); %Horizontal Distance
[H,V1] = meshgrid(h, v1);
t_reflect = @(h,v1,x) (sqrt(x.^2+4*h.^2)./v1); %Formula for arrival time
T_Reflect = t_reflect(H,V1,10); % Calculate Time At x=10
figure(1)
plot(v1, T_Reflect')
grid
legdph = strsplit(num2str(h, '%.0f '),' ');
legend(legdph);
xlabel('Velocity')
ylabel('Arrival Time')
figure(2)
plot(h, T_Reflect)
grid
legvel = strsplit(num2str(v1, '%.0f '),' ');
legend(legvel, 'Location','Nw');
xlabel('Depth')
ylabel('Arrival Time')

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

JDilla
JDilla 2015년 5월 10일

0 개 추천

Excellent code. I've seen the range of velocities which is good. Now I just want to have one velocity, against the range of velocities, if that makes any sense.
So the x axis will be 2500 linearly spaced to 4000, like it is. But instead of having multiple lines plotted, there should only be one line, as there should only be one output from the formula. This is because there is only one input, which is 3500 meters per second as v1.
how would I do this? ie v1 = 3500, but its plotted against x axis of velocities which are 2500 - 4000.
Need to do the same with depth, only have one line for one velocity v1 = 3500.
Sorry for changing my mind!

댓글 수: 3

No worries!
To fix it at one velocity = 3500 and one distance x = 10:
T_Reflect = t_reflect(h,3500,10); % Calculate Time At x=10, v1 = 3500
The plot is figure(2), but without the legend:
figure(2)
plot(h, T_Reflect)
grid
xlabel('Depth')
ylabel('Arrival Time')
JDilla
JDilla 2015년 5월 10일
I take it h in T_Reflect is meant to be capital H ? otherwise I get error vectors must be same length. If I use H it works.
And Figure 2 is looking good, but figure 1 is now a series of straight lines (which it should be) but I only need just the one.
Not really. I intended it to be ‘h’. If you want the function to be of one variable only for each plot, we have to do two separate calls to ‘t_reflect’.
I initially thought you only wanted it as I wrote it in my last Comment, with only figure(2) and only with the one line. Velocity and Distance are now fixed, so the only variable is Depth. As I understand it, with only one Velocity value, figure(1) is now out of the picture.
What do you want to do with figure(1)? To get one line in it, you would have to fix a value for Depth as well, and then let Velocity vary. Fixing Depth at 5 here, and with a separate call to the function (note the lower-case variable names indicating that they are vectors and not the matrices created by meshgrid), we get:
T_Reflect_1 = t_reflect(5,v1,10); % Calculate Time At x=10, h = 5
T_Reflect_2 = t_reflect(h,3500,10); % Calculate Time At x=10, v1 = 3500
so figure(1) then becomes:
figure(1)
plot(v1, T_Reflect_1')
grid
xlabel('Velocity')
ylabel('Arrival Time')
and figure(2):
figure(2)
plot(h, T_Reflect_2)
grid
xlabel('Depth')
ylabel('Arrival Time')

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Graphics Performance에 대해 자세히 알아보기

질문:

2015년 5월 7일

편집:

2015년 5월 11일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by