ode45 command matlab help
조회 수: 6(최근 30일)
1000*dV/dt+cd*1.225*V^2*A+200-T=0 this is the ode i have to currently solve for assignment due on the 11th of this month where T is defined by the for loop added below. Heres the question "Write a function into which you pass the end time and time step size that returns the time and speed array for a car initially at rest, speed equals 0.0 m/s, is accelerated along a runway " cd=0.5 and A=2
Jan 2018년 5월 9일
편집: Jan 2018년 5월 12일
Remember that Matlab's ODE integrators (as many other tools also) can handle smooth functions only: The automatic step size control gets deeply confused if the function to be integrated is not differentiable. See http://www.mathworks.com/matlabcentral/answers/59582#answer_72047. If you are lucky, the integrator stops with an error, but without luck, you get a result, which is dominated by the accumulated rounding error, because the step size is reduced until the discontinuity is hidden by the truncation error.
The numerically correct method is to stop the integration at the discontinuity and restart it. If the time is known in advance, e.g. as Tstop:
[t1, y1] = ode45(fcn1, [0, Tstop], y0);
[t2, y2] = ode45(fcn2, [Tstop, Tend], y1(end, :));
t = [t1; t2];
y = [y1; y2];
If the discontinuity depends of a certain position, use an event function to stop the integration and a while loop until t(end) is the wanted final time.
[EDITED] The question of your homework is not precise. Maybe a simple Euler method is sufficient already instead of a smart ODE integrator or symbolic integrations:
function [t, v] = YourFcn(tEnd, dt)
t = 0:dt:tEnd;
v0 = 0;
cd = 0.5;
A = 2;
v = zeros(size(t));
v(1) = v0; % Actually not needed because it is 0 already
for it = 2:numel(t)
% if t < 1, T = 10000*t; else, T = 10000; end -- easier:
T = 10000 * min(t(it), 1);
accel = (T - 200 - (cd * 1.225 * v(it-1) ^ 2 * A)) / 1000;
v(it) = v(it - 1) + accel * dt;
John BG 2018년 5월 11일
편집: John BG 2018년 5월 11일
this is John BG <mailto:email@example.com firstname.lastname@example.org>
the ODE is simple and it can be split into 2 parts:
1000*dV/dt+cd*1.225*V^2*A+200 - T
a basic 1st degree ODE that doesn't really need any solver to solve it, its just the integration of a polynomial:
The Torque applied
How does the Torque and its integral look like?
clear all;close all;clc
time_end=120 % 2 minute
cd = 0.5;
% time_step =input('Input end time');
% time_end= input('Input time step size');
T=10000*(t.*(t<1) + (t>=1).*(t<=50));
axis([-10 130 -100 10500])
title(' Torque and int(Torque)')
axis([-5 125 -100 5e6])
An example of real Torque is available in page 26 of Balaji Kamalammannan's Master Degree thesis
'Modelling and Simulation of Vehicle Kinematics and Dynamics (WITH MATLAB)'
Just split the needed integration
int(f1 + f2)= inf(f1) + int(f2)
syms dvdt v
(49*v^3)/240000 + v/5
v=v_without_T + T1
T1 being cumsum(T)
Since the integral of the Torque is already null at v=0, let's find the integration constant to meet the initial condition
v=(49*v^2)/80000 + 1/5+T1 + kv0
kv1=-.5 % to set v(0)=0
fv3=@(u) (49*u^2)/80000 + 1/5+T1k+ kv1 - u
fv3=@(u) (49*u^2)/80000 + 1/5+T1k+ kv1 - u;
axis([0 100 -100 900])
As expected the dominant term of the velocity, with the equation you use, is the Torque.
Torque is roughly proportional to fuel (or battery charge) consumption.
But your equation is for an ideal model, with the vehicle on flat terrain. In reality, only with certain minimum downhill angle, and not even with brand new bearings and everything working well, air drag, friction continuously reduces gained velocity thus further torque is required to keep speed constant.
if you find this answer useful would you please be so kind to consider marking my answer as Accepted Answer?
To any other reader, if you find this answer useful please consider clicking on the thumbs-up vote link
thanks in advance for time and attention