필터 지우기
필터 지우기

Plot the vector field of a first order ODE

조회 수: 4 (최근 30일)
Tanja Gesslbauer
Tanja Gesslbauer 2017년 6월 16일
편집: Loay Gouda 2020년 5월 21일
Good evening,
I have to solve the following problem via MatLab, and I'm stuck a little:
x' = x(r-e^x)
The goal is to plot the all the different vector field of this differential equation with varying r.
if true
[T, X] = meshgrid(0:0.1:5, -5:0.1:5);
dX = X*(r-exp(X));
dT = ones(size(dX));
quiver(T, X, dT, dX);
end
I tried it with meshgrid, but somehow it does not seem to work. I know how to plot equations in MatLab, and I know how to solve differential equations, but both, I don't know.
Do I need to define r as a vector? or do I just have to plot the differential equation?
I would be grateful for some help here :-)
Greetings, Tanja
  댓글 수: 1
Tanja Gesslbauer
Tanja Gesslbauer 2017년 6월 16일
Update: I tried it again differently
if true
[T, Y]=meshgrid(-5:0.1:5,-5:0.1:5);
dY=Y*(r-exp(x));
dT=ones(size(dY));
L=sqrt(1+dY.^2);
quiver(T, Y, dT./L, dY./L, 0.5)
axis tight
end
and even if I replace r with 1, 0 and -1 (just for trying out reasons) it doesn't work. So I'm guessing I need to define r differently?
Greetings

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

답변 (1개)

David Goodmanson
David Goodmanson 2017년 6월 17일
편집: David Goodmanson 2017년 6월 17일
Hi Tanja, Since the exponetial function creates such a wide range of values, I like your idea in the second code of plotting unit vectors. In that code, try
dY=Y.*(r-exp(Y));
It has exp(Y), which is what you meant instead of exp(x), but also
.* in place of *
  댓글 수: 2
Tanja Gesslbauer
Tanja Gesslbauer 2017년 6월 17일
Thank's a lot! This was such a stupid mistake, something that's not supposed to happen!
Now it works fine, I can try different values for r and it shows me different outcomes. Now I'm curious: is there a possibility in MatLab to get a visualisation in which is r runs from e.g. [-10, 10]?
Greetings, Tanja :-)
Loay Gouda
Loay Gouda 2020년 5월 21일
편집: Loay Gouda 2020년 5월 21일
Hello Tanja, So this is a bit late but to answer your question you can put the whole thing in a for loop for r = -10:10 And before you end the loop add after quiver ==> drawnow, pause("the time difference you want")
This will show a series of plots for different values of r that is updated on the same plot.
I hope you did find your answer back then and that this reply didn't help at all.

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

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by