# How to plot this equation to obtain the figure?

5 views (last 30 days)
soe min aung on 18 Dec 2019
Commented: soe min aung on 24 Dec 2019

#### 1 Comment

Walter Roberson on 18 Dec 2019
You have a bit of a problem: your has three independent inputs, and one output, so you need a 4-dimensional plot . The plot c that you show is for a fixed time, t1, not the general equation.
If you have the Symbolic Toolbox, probably the easiest approach is to use a piecewise() equation, subs() in a fixed time, and fplot() the result. If you do not have the Symbolic Toolbox, either use logical indexing to construct your answer, or else just compute over the three y ranges separately and concatenate them together.

Walter Roberson on 24 Dec 2019
N = 50; %subdivisions per dimension
xmin = -1; xmax = 101;
ymin = -160; ymax = 160;
tmin = 0; tmax = 3600;
xvec = linspace(xmin, xmax, N);
yvec = linspace(ymin, ymax, N);
tvec = linspace(tmin, tmax, N);
[X, Y, T] = ndgrid(xvec, yvec, tvec);
maskx = 0 <= X & X <= 100;
masky1 = -150 <= Y & Y < -50;
masky2 = -50 <= Y & Y < 50;
masky3 = 50 <= Y & Y <= 150;
xi = zeros(size(X));
random_time_idx = randi(length(tvec));
random_time = tvec(random_time_idx);
x_for_t = X(:,:,random_time_idx);
y_for_t = Y(:,:,random_time_idx);
zi_for_t = xi(:,:,random_time_idx) / xi0;
surf(x_for_t, y_for_t, zi_for_t)
xlabel('x (km)');
ylabel('y (km)');
zlabel('\$\frac{\zi(x,y,t1)}{\zi_0}', 'interpreter', 'latex')
title( sprintf('time = %.2f', random_time) );

#### 1 Comment

soe min aung on 24 Dec 2019
Thank you for your response. I have Symbolic Toolbox. Let me show you a plot form allwayzitzme@gmail.com which is the same your figure from your code. But It is different from the above picture. I want to get as above figure. But I can't try this. So I need your advice for this code. Please try sir,
clc
clear all
m = 30 ; n = 10 ;
x = linspace(0,100,m) ;
eta0 = 2 ;
L = 100 ;
W = 100 ;
v = 0.14 ;
t = 5.95 ;
y1 = linspace(-150,-50,n) ;
[X,Y1] = meshgrid(x,y1) ;
T1 = eta0*v*t/(2*L)*(1-cos(pi/50*X)).*(1-cos(pi/100*(Y1+150))) ;
y2 = linspace(-50,50,n) ;
[X,Y2] = meshgrid(x,y2) ;
T2 = eta0*v*t/L*(1-cos(pi/50*X)) ;
y3 = linspace(50,150,n) ;
[X,Y3] = meshgrid(x,y3) ;
T3 = eta0*v*t/(2*L)*(1-cos(pi/50*X)).*(1-cos(pi/100*(Y3-150))) ;
X = [X ; X; X] ;
Y = [Y1 ; Y2 ;Y3] ;
eta = [T1 ; T2 ; T3] ;
surf(X,Y,eta) ;

soe min aung on 23 Dec 2019

Walter Roberson on 23 Dec 2019
I did help you. I suggested two different strategies (Symbolic Toolbox or not), and two technical implementations for the non-symbolic strategy. Have you read the documentation about piecewise() and about logical indexing ?
soe min aung on 23 Dec 2019
Could you please give me matlab code example for this case.
Walter Roberson on 23 Dec 2019