surf plot - not sure how to make a matrix
Afficher commentaires plus anciens
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 commentaire
Matt Fig
le 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');
Réponse acceptée
Plus de réponses (1)
Sean de Wolski
le 14 Déc 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 commentaire
Tom
le 15 Déc 2011
Catégories
En savoir plus sur Surface and Mesh Plots dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!