答案 0 :(得分:1)
index=0;
time_axis=0:0.1:25; %i chose time step as 0.1 seconds
speed=zeros(1, numel(time_axis)); %this line is for memory allocation, its optional
for t=0:0.1:25 %we could also use a while loop on time_axis elements
index=index+1;
if t<5
speed(index)= 0.1553567*t^6-2.0416*t^5 ... %complete the formula
elseif t<15.4
speed(index)=0.0039.... %complete the formula
else
speed(index)=.... %complete the formula
end
end
plot(time_axis,speed); %you can use xlabel, ylabel and title functions to write labels
答案 1 :(得分:0)
您可以使用heaviside
函数,并通过组合指定域中的各个方程式来创建函数句柄。
eq1 = @(t) t.^6 + t.^5; % etc.
eq2 = @(t) t.^5 + t.^4; % etc.
eq3 = @(t) t.^2 + t; % etc.
f = @(t) eq1(t) + heaviside(t-5).*(eq2(t)-eq1(t)) + heaviside(t-15.4).*(eq3(t)-eq2(t));
t = 0:25;
y = f(t);