필터 지우기
필터 지우기

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.

채택된 답변

Walter Roberson
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.
  댓글 수: 1
ryecatcher
ryecatcher 2020년 2월 13일
Dear Sir:
Thank you very much for your excellent informational reply. I have added a dot in the code and it is working now:
previous wrong code:
S=T.^2 / (1 - Y.^2);
Now I have added a dot right before '/':
S=T.^2 ./ (1 - Y.^2);
The direction field comes out correctly. Thank you again!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Vector Fields에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by