Bernoulli differential equation moving electric car

Hello,
I am trying to plot this function in matlab dv/dt+K*v=-C*v^2 with K and C constants for this particular model.
I know it is a bernoulli equation but I don't know how to solve it exactly.
I am writing
f=@(t,v) -C*v^2-K*v;
[t,v]=ode23(f,[0,20],v0)
plot(t,v)
to evaluate the function between 0 and 20 seconds with an initial speed v0=30 m/s
Thank you

9 Comments

Yes that is defined. I can show the whole code.
ro=1.205; a=2.6; cd=0.34;K=0.05; m=1900; v0=33.333;
C=0.5*ro*a*cd;
f=@(t,v) -C*v^2-K*v;
[t,v]=ode23(f,[0,20],v0);
plot(t,v,'b')
Your code seems correct, according to the ODE you posted. Are you getting unexpected results?
The plot appears to be essentially a hyperbola.
Were you expecting something else?
Got it solved, it was a silly mistake I didn't divide the constants by the mass therefore I was having bad results.
Thank you guys.
So should it be:
f=@(t,v) -(C/m)*v^2-(K/m)*v;
instead?
Exactly, you are right. By the way, I am now trying to solve this second order equation:
y''+y+2t=0 / t∈[1,5] / y(1)=y'(1)=2
Is the code correctly written? Thank you
function rk=f(t,y)
rk=[y(2); -2.*t-y(1)];
end
timerange=[1 5];
initv=[2 2];
[t,y]=ode45(@f, timerange, initv)
plot(t,y(:,1));
Yes, the code is correct according to the equation.
Ok,
thanks bro

Sign in to comment.

Answers (0)

Categories

Find more on Numerical Integration and Differential Equations in Help Center and File Exchange

Asked:

on 7 May 2020

Edited:

on 10 May 2020

Community Treasure Hunt

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

Start Hunting!