Using events with ode45 to solve the initial velocity in the x-axis and plot the travel for an electron.

3 次查看(过去 30 天)
Hi there!
I've got a problem that is similar to one that I asked previously about the travel for an electron. This task requires me to plot the travel of an electron that enters a circle, with radius 1, with the initial coordinates of (1,0) and exits at (0,1). I'm supposed to use ode45 with the 'Events' options in combination with my function xvel, that (I'm not that sure of) detects when the x-coordinate is 0. I know that the initial velocity for the elextron is 0 along the y-axis, but unknow along the x-axis.
I've decided to write the coordinates in the form [x;y;u;v]. (x,y) = the position of the electron, (u,v)=the velocity of the electron.
tguess=[1;0;-1.7;0]; %I'm supposed to guess the initial velocity along the x-axis.
options=odeset('Events',@xvel);
[t,ux]=ode45(@particle,[0 2],tguess,options);
theta=linspace(0,2.*pi);
xp=cos(theta);
yp=sin(theta);
plot(xp,yp);
hold on
plot(ux(:,1),ux(:,2));
hold on
function [val,stopp,dir] = xvel(t,xv)
val=xv(1);%Does this only apply to the x-coordinate?
stopp=0;%Stop when x=0
dir=[-1;0];
end
function yprime = particle(t,y)
b=[0;0;1;0];
A=[0,0,1,0;0,0,0,1;0,0,0,1;0,0,-1,0];
yprime=A*y+b;
end
I've also been given the function yprime from the task. When I plot the figure, it's supposed to look like the figure below (excluding the dotted lines!).
But my figure turns out to look something like this.
I'm not that experienced with 'Events', which is why I'm struggling a lot here. I suspect that the problem lies around that area.
I appreciate any advice/ help I can get!
  1 个评论
Ibrahim Taha
Ibrahim Taha 2020-5-27
I've written a function that takes in a guess for the initial speed along the x-axis.
function pd = solv(u0)
theta=linspace(0,2.*pi);
xp=cos(theta);
yp=sin(theta);
plot(xp,yp);
hold on
tguess=[1;0;u0;0];
options=odeset('Events',@eventfunc);
[t,usol]=ode45(@particle,[0 2],tguess,options);
pd=usol(:,3);
plot(usol(:,1),usol(:,2))
hold on
end
But I've gotten a hint that I'm supposed to subtract [0;1] from "the point where the electron exits the circle". I don't seem to understand which point they're refering to by "the point which the electron exits".

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Ordinary Differential Equations 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by