MATLAB для цикла для 3 условий с одинаковой переменной «скорость» - PullRequest
0 голосов
/ 05 ноября 2018

Я часами пытался понять, как сделать этот код, но, похоже, ничего не работает. Может кто-нибудь показать, как написать код для этого уравнения

enter image description here

Ответы [ 2 ]

0 голосов
/ 05 ноября 2018

Вы можете использовать функцию 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);
0 голосов
/ 05 ноября 2018
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
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...