Graphing a 3D Plot in Matlab

• Nov 26th 2009, 01:20 PM
dillonmhudson
Graphing a 3D Plot in Matlab
Here is the code I have so far:

delete g286x08.txt; diary g286x08.txt
clear; clc; close all; echo on
% DMH
% Gilat 286/08
%
P= 4*pi(.032/2*pi*8.31.*T)^(3/2).*v^2.*exp((-.032.*v^2)/(2*8.31.*T)) ;
% R= 8.31
% M= .032
T=70:0.1:320 ;
v= 0:0.1:1000 ;
plot3(V,T,P)
grid on
%

echo off; diary off

where M is the molar mass of the gas in kg/mol, R=831 J/mol-K is the gas constant, T is the temperature in degrees K, and v is the molecules speed in m/s,

Here is the question:
Make a 3-D plot of P(v) as a function of v and T for V:[0,1000] (inclusive interval) and T:[70,320] in Kelvin for oxygen (molar mass .032 kg/mol)

Thank you very much!
• Nov 28th 2009, 03:29 AM
elbarto
Try this:

Code:

```n = 20;%resolution T=linspace(70,320,n) ; v= linspace(0,1000,n) ; [TT vv] = meshgrid(T,v); P = 4.*pi.*(.032./2.*pi.*8.31.*TT).^(3./2).*vv.^2.*exp((-.032.*vv.^2)./(2.*8.31.*TT)); surf(TT,vv,P) xlabel T ylabel v zlabel P grid on```
Elbarto
• Nov 28th 2009, 02:20 PM
dillonmhudson
It just says 'undefined variable T' and then says there is an error in P=....
• Nov 30th 2009, 03:50 AM
elbarto
T is defined on the second line so I don't know why u would be getting that message. Did u past all code inside a single mfile and run
• Nov 30th 2009, 08:44 AM
dillonmhudson
Yeah sorry dude, was trying not to copy and paste it, just so I could understand how you did it. But I rearranged it and got it to work, so thanks a lot dude. i appreciate it!