이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
Blank plot in matlab
조회 수: 61 (최근 30일)
이전 댓글 표시
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')
채택된 답변
Star Strider
2019년 6월 25일
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
MOUNIBA REDAH
2019년 6월 25일
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
2019년 6월 25일
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
2019년 6월 25일
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
2019년 6월 25일
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
2019년 6월 25일
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
2019년 6월 25일
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
2019년 6월 25일
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
2019년 6월 25일
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
2019년 6월 25일
편집: MOUNIBA REDAH
2019년 6월 25일
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
2019년 6월 25일
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
2019년 6월 26일
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
![Untitledp.png](https://www.mathworks.com/matlabcentral/answers/uploaded_files/226425/image.png)
Star Strider
2019년 6월 26일
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
2019년 6월 26일
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
![untitled.jpg](https://www.mathworks.com/matlabcentral/answers/uploaded_files/226505/image.jpeg)
MOUNIBA REDAH
2019년 6월 26일
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![Untitledp.png](https://www.mathworks.com/matlabcentral/answers/uploaded_files/226506/image.png)
![Untitledp.png](https://www.mathworks.com/matlabcentral/answers/uploaded_files/226506/image.png)
Star Strider
2019년 6월 26일
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
2019년 6월 27일
ok. Do you mean I should changes This values of ‘1./[1 5 9]'’ into mt own context
MOUNIBA REDAH
2019년 6월 27일
편집: MOUNIBA REDAH
2019년 6월 27일
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![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/226647/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/226647/image.png)
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 :
![Capturesi.PNG](https://www.mathworks.com/matlabcentral/answers/uploaded_files/226648/image.png)
Ps The code attached
Star Strider
2019년 6월 27일
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)
추가 답변 (0개)
참고 항목
태그
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 MathWorks 사이트 방문이 최적화되지 않았습니다.
미주
- América Latina (Español)
- Canada (English)
- United States (English)
유럽
- 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)
아시아 태평양
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)