You are now following this question
- You will see updates in your followed content feed.
- You may receive emails, depending on your communication preferences.
Blank plot in matlab
65 views (last 30 days)
Show older comments
hello can you please help me?? when i type this code i only get a balnk plot
i don`t know where is my mistake
the code
sigma0=0;
el= 0.5;
L= 1 ;
h= 0.5 ;
a= 1;
N= 3;
g=10;
rho=1000;
Z0=0;
t=0:0.01:5;
x=0:0.02:el;
y=0:0.02:L;
[X,Y]=meshgrid (x,y);
sigma=0;
T=3*pi/4;
for n=0:N
for m=0:N
A=pi*((m/el)^(2)+(n/L)^(2))^(0.5);
B=(g*A+(sigma/rho)*A^3)*atan(A*h);
C=B^(0.5);
Z=a*cos(C.*T).*cos((m*pi/el).*X).*cos((n*pi/L).*Y);
Zs=Z0+Z;
Z0=Zs;
end
end
m=3;
n=4;
A=pi*((m/el)^(2)+(n/L)^(2))^(0.5);
B0=(g*A+(sigma0./rho)*A^3)*atan(A*h);
C0=(B0.^(0.5));
Z0=(a.*cos(C0.*T)).*cos((m*pi/el).*X).*(cos((n*pi/L).*Y));
figure
subplot(221)
plot(t,length(Z0));
xlabel(' temps s');
ylabel(' élévation z(x,y)y');
title(' sans tension superficielle');
legend('sigma0')
Accepted Answer
Star Strider
on 25 Jun 2019
The immediate problem is:
plot(t,length(Z0));
since the length function will produce a scalar, and you can only plot a scalar using a marker. (The plot function plots lines between two defined points, and a scalar has only one.)
Beyond that, however, ‘Z0’ is not a function of ‘t’, and has entiely different dimensions as the result, so you cannot plot it as a function of ‘t’.
This works:
plot(Z0);
however it is likely not the result you want. You need to fix that problem.
22 Comments
MOUNIBA REDAH
on 25 Jun 2019
thank you for your answer
i wrote what you told me to do but now there is a new error
Z0=(a.*cos(C0.*T.*t)).*cos((m*pi/el).*X).*(cos((n*pi/L).*Y))
the error is Matrix dimensions must agree.
Star Strider
on 25 Jun 2019
I did not tell you to write anything!
I have no idea what you are doing, or what you want to do. Note that ‘T’ is a scalar, and ‘X’ and ‘Y’ are (51x26) matrices, and ‘t’ is a (1x501) vector. It is not possible to multiply them, because they are not conformable to matrix multiplication, using either array (element-wise) or matrix multiplication.
There may be a way to do what you want, however I would need to know what that is.
MOUNIBA REDAH
on 25 Jun 2019
sorry for disturbing you, i am new to matlab
i want to plot z0 in terms of t
the expression of z0 is
Z0=acos(C0.T. t) .cos((m.π.x )/el).cos((n.π.y)/L)
thank you a lot
Star Strider
on 25 Jun 2019
Disturbing me is not the issue.
The problem is that this term:
cos((m.π.x)/el).cos((n.π.y)/L)
is going to form a matrix with the dimensions of ‘x’ and ‘y’. You cannot then plot that by multiplying it by:
acos(C0.T.t)
as a function of your vector ‘t’, since that adds a third dimension.
What problem are you originally trying to solve?
MOUNIBA REDAH
on 25 Jun 2019
i am studying the effect of capillarity on the elevation of the free surface
in the equation Z0 is the free surface , sigma is the capillarity
Star Strider
on 25 Jun 2019
O.K.
What I intended is that I would like to see how that equation was originally implemented, and the context. We are missing some information that would likely be helpful.
MOUNIBA REDAH
on 25 Jun 2019
okey i wil try to give you an idea the only thing is that my subject is in french so i will need to do some translation
Star Strider
on 25 Jun 2019
I just need to know how they implemented your function of Z0(t,x,y) with respect to plotting it as a function ot ‘t’.
That is not at all obvious to me.
MOUNIBA REDAH
on 25 Jun 2019
Edited: MOUNIBA REDAH
on 25 Jun 2019
The wavenumbers A are worth: A=pi*((m/el)^(2)+(n/L)^(2))^(0.5)
(m, n) are two positive integers whose mode of vibration is determined with a pulsation given by the following dispersion relation: (B)^2=(g*A+(sigma./rho)*A^3)*atan(A*h)
The elevation of the free surface is given by:Z(x,y,t)=(a.*cos(B.*T*t)).*cos((m*pi/el).*x).*(cos((n*pi/L).*y))
The expression obtained shows that all the fluid particles lying on the free surface vibrate in phase, but the amplitude of these sinusoidal movements depends on the spatial coordinates x and y.
time dependence is assumed to be harmonic in which the velocity potential satisfies the initial condition Z (x, y,0) = 0.
For a given value of x the surface of the liquid moves up and down, and for a given value of time t, the shape of the surface is a cosine curve, such a wave does not propagate . In fact, the free surface oscillates vertically. As in the case of the eigenmodes of the vibration of a solid structure, the sloshing modes appear as stationary surface waves due to the confinement of the liquid by the walls of the reservoir.
my goal is to study tthe effect of sigma on Z in a time t
Star Strider
on 25 Jun 2019
You can easily do that for individual values of ‘x’ and ‘y’ as a function of ‘t’.
I would just do this:
sigma0=0;
el= 0.5;
L= 1 ;
h= 0.5 ;
a= 1;
N= 3;
g=10;
rho=1000;
Z0=0;
t=0:0.01:5;
x=0:0.02:el;
y=0:0.02:L;
[X,Y]=meshgrid (x,y);
sigma=0;
T=3*pi/4;
% for n=0:N
% for m=0:N
% A=pi*((m/el)^(2)+(n/L)^(2))^(0.5);
% B=(g*A+(sigma/rho)*A^3)*atan(A*h);
% C=B^(0.5);
% Z=a*cos(C.*T).*cos((m*pi/el).*X).*cos((n*pi/L).*Y);
% Zs=Z0+Z;
% Z0=Zs;
%
% end
% end
m=3;
n=4;
A=pi*((m/el)^(2)+(n/L)^(2))^(0.5);
B0=(g*A+(sigma0./rho)*A^3)*atan(A*h);
C0=(B0.^(0.5));
Z0=(a.*cos(C0.*T)).*cos((m*pi/el).*X).*(cos((n*pi/L).*Y));
figure
subplot(221)
hold all
for k1 = 1:numel(x)
for k2 = 1:numel(y)
Z0=(a.*cos(C0.*T*t)).*cos((m*pi/el).*x(k1)).*(cos((n*pi/L).*y(k2)));
plot(t, Z0)
end
end
xlabel(' temps s');
ylabel(' élévation z(x,y)y');
title(' sans tension superficielle');
legend('sigma0')
That at least produces a plot of ‘Z0’ as a function of ‘t’ for all values of ‘x’ and ‘y’.
That is the best I can do.
MOUNIBA REDAH
on 25 Jun 2019
okey i will try to do it on MATLAB thank you for your help you are great
Star Strider
on 25 Jun 2019
As always, my pleasure.
I simply have no idea what you want to do.
MOUNIBA REDAH
on 26 Jun 2019
what i want to do is to have result like this figure In this figure we have sigma0=0 , sigma1=0.01,sigma2=0.2
Star Strider
on 26 Jun 2019
I do not know how to get that in the context of your code (because I do not understand what you are calculating), however getting that sort of result is straightforward.
Example —
t = linspace(0, 1.8, 150);
y = cos(1./[1 5 9]' * 2*pi*t*5);
figure
plot(t, y)
This does simple vector-matrix multiplication of the column vector ‘1./[1 5 9]'’ by the row vector ‘2*pi*t*5’ and then plots the matrix the sin() functon of that matrix creates. (Here, the sin() function calculates across the rows.)
MOUNIBA REDAH
on 26 Jun 2019
Your answer got me to do some research in the context of my subject and then I found that sometimes they take x and y are zero So the expression of Z0 become Z0=(a.*cos(C0.*T.t)
when I excuted This equation I got this result
Star Strider
on 26 Jun 2019
Looks good to me for those values.
MOUNIBA REDAH
on 26 Jun 2019
Yes , Thank you so much for your help ,you saved me
only one more thing I have to plot 3cases sigma0=0 , sigma1=0.01, sigma1=0.2 like in the previous figure
Star Strider
on 26 Jun 2019
It is difficult for me to interpret your code (and to be honest, I still do not understand it). It seems to me that you would need to use something similar to the code in my previous Comment and use the appropriate values for sigma in the ‘1./[1 5 9]'’ column vector to do that plot.
MOUNIBA REDAH
on 27 Jun 2019
ok. Do you mean I should changes This values of ‘1./[1 5 9]'’ into mt own context
Star Strider
on 27 Jun 2019
Yes.
Perhaps to: [0 0.01 0.2]'.
MOUNIBA REDAH
on 27 Jun 2019
Edited: MOUNIBA REDAH
on 27 Jun 2019
hello Star Strider a colegue had help me and give me some information the reason of Loops in my code is because there is a summuation in my equation
And gave me the code of It only It is not using Plot ,This example in using SURF because the result that gave me is in 3D
My qustion it is possible to modify in this code in order to plot the graph I Want I mean to change the eqaution above by this one :
Ps The code attached
Star Strider
on 27 Jun 2019
I have no clue as to what you want.
Try this:
t = linspace(0, 1); % Use Correct Time Limits
omega = rand(4); % Use Correct Values
for k1 = 1:4
for k2 = 1:4
Z(k1,k2,:) = acos(omega(k1,k2)*t);
end
end
Zs = sum(sum(Z,2),1);
Zs = squeeze(Zs);
figure
plot(t, Zs)
More Answers (0)
See Also
Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!An Error Occurred
Unable to complete the action because of changes made to the page. Reload the page to see its updated state.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom(English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)