필터 지우기
필터 지우기

surf plot - not sure how to make a matrix

조회 수: 2 (최근 30일)
Tom
Tom 2011년 12월 14일
Hi, I don't understand how to make the necessary matrix to make a surf graph using two variables. I've done simple surf graphs without having to consciously create any matrices, but this time it isn't working. Here's my code,
rho_air=1.2041; %density of air at 20 degrees celsius and 101.325 kPa (kg/m^3)
c=343.26; %speed of sound in dry air at 20 degrees celsius(m/s)
h=linspace(0.001,0.03,500); %height of resonator cavity (m)
w=0.03; %width of resonator cavity (m)
l=0.03; %length of resonator cavity (m)
V=h*w*l; %volume of resonator cavity (m^3)
a=0.003; %radius of neck (m)
L=0.002; %length of neck (m)
Le=L+(0.85+0.6)*a; %effective length of neck after taking the end correction into account, assuming the opening is unflanged
S=pi*a^2; %surface area of neck opening (m^2)
s=(rho_air*c^2*S^2)./V; %elastic stiffness
m=rho_air*S*Le;
f=linspace(500,1000,500);
k=(2*pi*f)/c; %wavenumber in air
Rr=(rho_air*c*k.^2*S^2)*(4*pi); %Radiation resistance assuming neck opening is unflanged
w=2*pi*f; %angular frequency
Zm=Rr+1i*(w*m-s./w); %input mechanical impedance assuming no contribution from wall losses
Zmi=imag(Zm); %imginary part of Zm
surf(f,h,Zmi)
set(gca,'LineWidth',2)
hleg=legend('Imaginery part of Input Mechanical Impedance');
set(hleg,'Location','NorthWest');
set(hleg,'FontSize',22);
set(gca,'FontSize',22);
xlabel ('Frequency (Hz)');
ylabel ('Height of resonator cavity');
zlabel ('Input Mechanical Impedance');
  댓글 수: 1
Matt Fig
Matt Fig 2012년 11월 2일
Hi, I don't understand how to make the necessary matrix to make a surf graph usin g two variables. I've done simple surf graphs without having to consciously create any matrices, but this time it isn't working. Here's my code,
rho_air=1.2041; %density of air at 20 degrees celsius and 101.325 kPa (kg/m^3)
c=343.26; %speed of sound in dry air at 20 degrees celsius(m/s)
h=linspace(0.001,0.03,500); %height of resonator cavity (m)
w=0.03; %width of resonator cavity (m)
l=0.03; %length of resonator cavity (m)
V=h*w*l; %volume of resonator cavity (m^3)
a=0.003; %radius of neck (m)
L=0.002; %length of neck (m)
Le=L+(0.85+0.6)*a; %effective length of neck after taking the end correction into account, assuming the opening is unflanged
S=pi*a^2; %surface area of neck opening (m^2)
s=(rho_air*c^2*S^2)./V; %elastic stiffness
m=rho_air*S*Le;
f=linspace(500,1000,500);
k=(2*pi*f)/c; %wavenumber in air
Rr=(rho_air*c*k.^2*S^2)*(4*pi); %Radiation resistance assuming neck opening is unflanged
w=2*pi*f; %angular frequency
Zm=Rr+1i*(w*m-s./w); %input mechanical impedance assuming no contribution from wall losses
Zmi=imag(Zm); %imginary part of Zm
surf(f,h,Zmi)
set(gca,'LineWidth',2)
hleg=legend('Imaginery part of Input Mechanical Impedance');
set(hleg,'Location','NorthWest');
set(hleg,'FontSize',22);
set(gca,'FontSize',22);
xlabel ('Frequency (Hz)');
ylabel ('Height of resonator cavity');
zlabel ('Input Mechanical Impedance');

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

채택된 답변

the cyclist
the cyclist 2011년 12월 14일
I think you need to make a grid of your "f" and "h" variables, and calculate off the grid:
rho_air=1.2041; %density of air at 20 degrees celsius and 101.325 kPa (kg/m^3)
c=343.26; %speed of sound in dry air at 20 degrees celsius(m/s)
h=linspace(0.001,0.03,500); %height of resonator cavity (m)
f=linspace(500,1000,500);
[ff,hh] = meshgrid(f,h);
w=0.03; %width of resonator cavity (m)
l=0.03; %length of resonator cavity (m)
V=hh*w*l; %volume of resonator cavity (m^3)
a=0.003; %radius of neck (m)
L=0.002; %length of neck (m)
Le=L+(0.85+0.6)*a; %effective length of neck after taking the end correction into account, assuming the opening is unflanged
S=pi*a^2; %surface area of neck opening (m^2)
s=(rho_air*c^2*S^2)./V; %elastic stiffness
m=rho_air*S*Le;
k=(2*pi*ff)/c; %wavenumber in air
Rr=(rho_air*c*k.^2*S^2)*(4*pi); %Radiation resistance assuming neck opening is unflanged
w=2*pi*ff; %angular frequency
Zm=Rr+1i*(w*m-s./w); %input mechanical impedance assuming no contribution from wall losses
Zmi=imag(Zm); %imginary part of Zm
surf(ff,hh,Zmi)
set(gca,'LineWidth',2)
hleg=legend('Imaginery part of Input Mechanical Impedance');
set(hleg,'Location','NorthWest');
set(hleg,'FontSize',22);
set(gca,'FontSize',22);
xlabel ('Frequency (Hz)');
ylabel ('Height of resonator cavity');
zlabel ('Input Mechanical Impedance');
Note in particular my addition of the meshgrid() command.
  댓글 수: 1
Tom
Tom 2011년 12월 15일
Many thanks, that's perfect.

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

추가 답변 (1개)

Sean de Wolski
Sean de Wolski 2011년 12월 14일
Yes, h,f,Zmi are all 1x500 row vectors. surf requires matrices, i.e. at least 2x2.
Does changing surf() to scatter3() do what you want?
scatter3(f,h,Zmi)
  댓글 수: 1
Tom
Tom 2011년 12월 15일
Thanks I did want a surf, but it's good to know about scatter 3 too.

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

카테고리

Help CenterFile Exchange에서 General Physics에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by