How to set y to different functions depending on the limits of T

1 visualización (últimos 30 días)
So I'm trying to program this into matlab:
where ai is 0.5 and a0 is 0.3. I have tried using this code for it but I'm having difficulty with the (-10 <= T && T <= 10) part. Many Thanks!
T = -20:0.5:20;
ai = 0.5;
a0 = 0.3;
if T <= -10
y = ai
end
if (-10 <= T && T <= 10)
y = ai + (a0 - ai)*((T+10)/20)
end
if 10 <= T
y = a0
end
plot(T, y, 'bo-');
grid on;

Respuesta aceptada

Alan Stevens
Alan Stevens el 2 de Dic. de 2020
Editada: Alan Stevens el 2 de Dic. de 2020
Might be easier as
T = -20:0.5:20;
ai = 0.5;
a0 = 0.3;
y = ai + (a0 - ai)*((T+10)/20);
id = find(T<=-10);
y(id) = ai;
id = find(10<=T);
y(id) = a0;
plot(T, y, 'bo-');
grid on;

Más respuestas (0)

Categorías

Más información sobre Octave en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by