A newbie question: quiver failed to draw direction field of differential equation with 'Warning: Matrix is singular to working precision'
4 次查看(过去 30 天)
显示 更早的评论
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.
0 个评论
采纳的回答
Walter Roberson
2020-2-13
[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.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Vector Fields 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!