Why Does My MATLAB Code Generate a Singular Matrix Warning?

  • Context: MATLAB 
  • Thread starter Thread starter xpack
  • Start date Start date
Join the discussion
Ask a follow-up here, or get your own question answered by working scientists, mathematicians and engineers — people, not an autocomplete.
Real named experts · corrections over time · the nuance an AI answer skips
2 replies · 3K views
xpack
Messages
37
Reaction score
0
I have this question:

http://img7.imageshack.us/img7/1399/52987960.png

And From this I created this:
Code:
delete g286x08.txt; diary g286x08.txt
clear; clc; close all; echo on
%
%Gilat 286/08
%

R=8.31;
M=0.032;
x=0:20:1000;
y=70:5:320;
[X Y]=meshgrid(x,y);

Z=4*pi*(M./(2*pi*R*Y)).^(3./2)*X.^2.*exp(-M*X.^2)/(2*R*Y);

surf(X,Y,Z)

xlabel('Molecules Speed(m/s)'); ylabel('Temperature'); zlabel('Probability')
%
echo off; diary off

And when I run it I get

Code:
%
%Gilat 286/08
%
R=8.31;
M=0.032;
x=0:20:1000;
y=70:5:320;
[X Y]=meshgrid(x,y);

Z=4*pi*(M./(2*pi*R*Y)).^(3./2)*X.^2.*exp(-M*X.^2)/(2*R*Y);
Warning: Matrix is singular to working precision. 
> In g286x08 at 13

surf(X,Y,Z)

xlabel('Molecules Speed(m/s)'); ylabel('Temperature'); zlabel('Probability')
%
echo off; diary off

And this image
http://img194.imageshack.us/img194/9489/30221576.jpg

I know there should be something plotted here. Can someone help me?
 
Last edited by a moderator:
Physics news on Phys.org
There is problem in this line:

Code:
Z=4*pi*(M./(2*pi*R*Y)).^(3./2)*X.^2.*[B]exp(-M*X.^2)/(2*R*Y)[/B];

it should be: exp((-M * X.^2) ./ (2 * R * Y)

To avoid mistyping, i think you should disaggregate your eq. (e.g A = 2 * R * Y ; B = (M ./ (pi * A)).^(3/2);). It is easier to debug. :) That is my exp in my sim course.
 
Ugh I hate when I do stupid stuff like this. Thank you very much!