Filter löschen
Filter löschen

surf plot - not sure how to make a matrix

2 Ansichten (letzte 30 Tage)
Tom
Tom am 14 Dez. 2011
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 Kommentar
Matt Fig
Matt Fig am 2 Nov. 2012
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');

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

the cyclist
the cyclist am 14 Dez. 2011
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.

Weitere Antworten (1)

Sean de Wolski
Sean de Wolski am 14 Dez. 2011
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 Kommentar
Tom
Tom am 15 Dez. 2011
Thanks I did want a surf, but it's good to know about scatter 3 too.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu General Physics finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by