MATLAB: A newbie question: quiver failed to draw direction field of differential equation with ‘Warning: Matrix is singular to working precision’

"warning: matrix is singular to working precision"differential equationsdirection fieldquiverslope field

Dear All:
I am using web version MatLab to try to draw direction field for 1st order differential equation by using quiver function. Sometimes the direction field was successfully plotted, but sometimes failed, with warning message: "Warning: Matrix is singular to working precision".
For example, this code below susscessfully plotted the direction field of DE(y'=y^2):
% y'=y^2
[T, Y]=meshgrid(-2:0.2:2, -3:0.5:3)
S=Y.^2;
L=sqrt(1+S.^2);
quiver(T, Y, 1./L, S./L, 0.3), axis tight
xlabel 't', ylabel 'y'
title 'Direction Field for dy/dt = y^2'
However, this code failed when I tryied to plot y'=t^2/(1-y^2):
% y'=t^2/(1-y^2)
[T, Y]=meshgrid(-3:0.1:3, -3:0.1:3)
S=T.^2/(1. - Y.^2);
L=sqrt(1+S.^2);
quiver(T, Y, 1./L, S./L, 0.3), axis tight
xlabel 't', ylabel 'y'
title 'Direction Field for dy/dt = t^2/(1-y^2)'
Ths plot is blank, with message: "Warning: Matrix is singular to working precision". The expected direction field is attached as a picture.
Thank you very much for your help. I greatly appreciate it.

Best Answer

[T, Y]=meshgrid(-3:0.1:3, -3:0.1:3)
T and Y are going to be equal size matrices after that.
S=T.^2/(1. - Y.^2);
Each element of T is squared individually. Each element of Y is squared individually and that is subtracted from 1.
Now you take the two matrices and you ask to do least squared fitting of the two together, very similar to what you would get from
(T.^2) * pinv(1. - Y.^2)
where the * operator here is algebraic matrix multiplication, not element-by-element multiplication.
I would suggest to you that you do not want to do least-squared fitting of the two matrices, and that what you want instead is to do element-by-element division. Element-by-element division is the ./ operator, not the / operator.