Ask your own question, for FREE!
Mathematics 15 Online
OpenStudy (usukidoll):

dan, I love you

OpenStudy (usukidoll):

OpenStudy (usukidoll):

@dan815 the file I have so far...it's basic, but that's all there is according to the example I was given... Only the task is to set r=1 and K=20 fixed which I was trying to do but the code keeps going whacko

OpenStudy (usukidoll):

if I remove r =1 and K=20, it's fine, but that's not what my goal is.

OpenStudy (dan815):

function f=ram(ry,y,K) f=ry(1-y/K);

OpenStudy (dan815):

well what do u wanna do to it

OpenStudy (dan815):

i dont see anything wrong with it

OpenStudy (usukidoll):

the task issss Solve the logistic DE dy/dt= ry(1-y/K) with r=1, K=20 % initial conditions y(0)= 5, 10, 15, 20, 25, (use a for loop) % plotting the solutions on the same figure for t in [0 10]

OpenStudy (dan815):

ok so rewrite the equatio now

OpenStudy (dan815):

u are missing * sign in there

OpenStudy (usukidoll):

which I noticed there are three variables, r,y, and K. If I do something like function f=ram(r,y,K) f=ry(1-y/K); K=20; r=1; it won't work. if I do function f=ram(ry,y,K) f=ry(1-y/K); it works but I need to have K=20 and r=1 fixed and that's not what is going on here If I do function f=ram(ry,y,K) f=ry(1-y/K); K=20; r=1; Matlab whines

OpenStudy (dan815):

and ry is not a paremeter is it

OpenStudy (dan815):

isnt it r*y*(1-y)/K)

OpenStudy (usukidoll):

star sign? oh shxxx

OpenStudy (usukidoll):

one sec

OpenStudy (dan815):

is ry 1 variable?

OpenStudy (usukidoll):

matlab needs to make their fonts bigger I swear

OpenStudy (usukidoll):

well I saw r y and K. I thought it was 3?

OpenStudy (dan815):

hold on refine your function with a t input, u need that when u use ode45

OpenStudy (usukidoll):

so it's t y K?

OpenStudy (usukidoll):

anyway >> ram(1,1, 20) ans = 0.9500 >> if I just solve XD

OpenStudy (usukidoll):

OH WAIT. hold on

OpenStudy (dan815):

you cant do that, this is just dy/dt, its only telling u the slope

OpenStudy (dan815):

btw ode45 is just a nurmerical method, our prof made us once write the code behind ode45 and the 90 or something its pretty straight forwad just different step sizes for the approximations

OpenStudy (usukidoll):

pft ... doing ram(1,y,20) on the code makes it scream

OpenStudy (dan815):

so if u are ever having trouble u can just write your own numerical method and it shud be fine

OpenStudy (usukidoll):

but I need a graph...

OpenStudy (dan815):

yeah okay

OpenStudy (dan815):

wait lets start over...

OpenStudy (usukidoll):

k

OpenStudy (dan815):

the task issss Solve the logistic DE dy/dt= ry(1-y/K) r=1, K=20 % initial conditions y(0)= 5, 10, 15, 20, 25,(use a for loop) % plotting the solutions on the same figure for t in [0 10]

OpenStudy (usukidoll):

mhm but there's r y and K in there and we have to let it be fixed at r=1 and K=20

OpenStudy (dan815):

function f=ram(t,y) r=1 K=20 f=r*y*(1-y/K); end

OpenStudy (usukidoll):

function f=ram(t,y) f=r*y*(1-y/K); K=20; r=1; end ?

OpenStudy (usukidoll):

[tv f]=ode45('ram',[0 5],1); Undefined function or variable "r". Error in ram (line 2) f=r*y*(1-y/K); Error in odearguments (line 88) f0 = feval(ode,t0,y0,args{:}); % ODE15I sets args{1} to yp0. Error in ode45 (line 114) [neq, tspan, ntspan, next, t0, tfinal, tdir, y0, f0, odeArgs, odeFcn, ... I will kill this thing

OpenStudy (usukidoll):

the example code for the graph is [tv f]=ode45('fun',[0 5],1); plot(tv,f,'-') title('y''=-ty/sqrt(2-y^2), y(0)=1, t in [0, 5]') grid axis([0 5 0 1]) so I'm just doing the first two for now with [tv f]=ode45('ram',[0 5],1); plot(tv,f,'-') and I'm getting messed up

OpenStudy (usukidoll):

yup proof I need glasses... I was aiming to type, dan I need you. x.x omg fml not my night

OpenStudy (dan815):

http://prntscr.com/60wmu3

OpenStudy (dan815):

does it gotta look something like that

OpenStudy (usukidoll):

getting therer my scripts were running wild

OpenStudy (usukidoll):

yeah that graph is right...

OpenStudy (dan815):

okay heres the code i used so far

OpenStudy (dan815):

function out=usukicode() for i=[5,10,15,20,25] timerange=[0 10]; initialcond=i [t,y]=ode45(@ram,timerange, initialcond) plot(t,y) hold all; end end function f=ram(t,y) f=y.*(1-y./20); end

OpenStudy (dan815):

all in 1 file and named it usukicode.m

OpenStudy (dan815):

u can make that forloop a little more classy by i=5:5:25

OpenStudy (usukidoll):

ok, but what happens if r =2?

OpenStudy (dan815):

ok if u wanna pass that in too then

OpenStudy (dan815):

do u have to be able to pass it in? or u just wanna see with a new r

OpenStudy (usukidoll):

hold on let me try get r = 2 on this one ^_^ and if I crash I'll let you know.

OpenStudy (dan815):

r=2 : http://prntscr.com/60wp24 r=1 : http://prntscr.com/60wmu3

OpenStudy (dan815):

a faster convergence

OpenStudy (usukidoll):

wtf all I got is just one graph T___T!

OpenStudy (dan815):

oh u want it in differnt graph?

OpenStudy (usukidoll):

no all lines have to be in one graph... why do I only have 1?

OpenStudy (dan815):

lol what even is that

OpenStudy (usukidoll):

OpenStudy (dan815):

OpenStudy (dan815):

save and pass usukicode(r) for r=1

OpenStudy (dan815):

oh i see initial cond is not 1

OpenStudy (dan815):

its i

OpenStudy (usukidoll):

XD! told ya matlab needs to have bigger fonts

OpenStudy (usukidoll):

OpenStudy (dan815):

yeah

OpenStudy (usukidoll):

what the rabbit.. if I input 2 into the function, the code displays a red warning

OpenStudy (dan815):

its working for me

OpenStudy (dan815):

maybe u shud define the ram function in another file instead of under the code like i did

OpenStudy (dan815):

i have it defined in 2 files so im not sure which instance its refering to

OpenStudy (usukidoll):

oh like a secondary

OpenStudy (usukidoll):

gotcha

OpenStudy (usukidoll):

got em function out = nike() for i=[5,10,15,20,25] timerange=[0,10] initialcond=i [t,y]=ode45(@card,timerange,initialcond) plot(t,y) hold all; end end function f=card(t,y) f=2*y*(1-y/20) end

OpenStudy (usukidoll):

OpenStudy (usukidoll):

looks like the graphs are retracting and the 20 is the equilibrium

OpenStudy (usukidoll):

it has something to do with the population... eh I can type that later.

OpenStudy (usukidoll):

xlabel time ylabel population is missing but that's ok. I can always fix it... I know that the original problem has 2 equlibriums 0 and K and the graphs have something to do with the population when it's going towards the equilibrium or something like that

OpenStudy (dan815):

yep it does

OpenStudy (dan815):

there is a saturation point for this ode it can be used to model some population growths

OpenStudy (usukidoll):

do you know what a bifurcation graph is?

OpenStudy (dan815):

i dunno what bifucation means

OpenStudy (dan815):

but the main things to observe on your graph is there is a point where its increasing exponentially then decreasing exponentially

OpenStudy (dan815):

just like population growths, when u are far from the lands supporting population u will increase like a normal interest rate growth function

OpenStudy (dan815):

but as u get closed to the saturation point the growth rate goes lower and lower and evnetually decays

OpenStudy (dan815):

closer*

OpenStudy (dan815):

oh ok ya i know this ode :)

OpenStudy (usukidoll):

and then the population is messed up

OpenStudy (usukidoll):

what about graphing stability?

OpenStudy (dan815):

0 is a unstable point

OpenStudy (dan815):

i dunno what u call it exactly but

OpenStudy (dan815):

its the one where things diverge away from

OpenStudy (usukidoll):

yeah but do you graph by hand x)

OpenStudy (dan815):

u wanna graph what happens at 0?

OpenStudy (usukidoll):

ya

OpenStudy (dan815):

add more inital conditions then

OpenStudy (usukidoll):

but a different function

OpenStudy (usukidoll):

like dx/dt = x(x^2-a^2) besides x =0,-a,a which are the equilibrium points... how do I graph it manually?

OpenStudy (dan815):

graph what exactly?

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!