現在この質問をフォロー中です
- フォローしているコンテンツ フィードに更新が表示されます。
- コミュニケーション基本設定に応じて電子メールを受け取ることができます。
Blank plot in matlab
65 ビュー (過去 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 月 25 日
okey i will try to do it on MATLAB thank you for your help you are great
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
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
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
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
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
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!エラーが発生しました
ページに変更が加えられたため、アクションを完了できません。ページを再度読み込み、更新された状態を確認してください。
Web サイトの選択
Web サイトを選択すると、翻訳されたコンテンツにアクセスし、地域のイベントやサービスを確認できます。現在の位置情報に基づき、次のサイトの選択を推奨します:
また、以下のリストから Web サイトを選択することもできます。
最適なサイトパフォーマンスの取得方法
中国のサイト (中国語または英語) を選択することで、最適なサイトパフォーマンスが得られます。その他の国の 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 (한국어)