plot function in a specific interval while the other interval function is equal to zero

Réponses (1)

See if this helps to understand how to solve your homework:
t=1:.1:10;
g=t.^2.*(t>=1 & t<5) + t.*(t>=5 & t<=10);
plot(t,g)

5 commentaires

Hint: One of your time interval should use "|" instead of "&".
thankyou madhan for your response.
actually i tried your code but no change. your code gives the same results as no constraints.
i appreciate if you could help
i need y(t) equal to zero when no input exists
this is my code:
clc; clear all; close all
syms y(t) a b
eqn = diff(y,t,2) == 0.5*(1-diff(y,t,1)-2*y); % 2y''+y'+2y=g(t)
Dy = diff(y,t);
cond = [y(0)==0, Dy(0)==0];
y(t) = dsolve(eqn,cond)
t=0:pi/100:15*pi;
subplot(2,1,1)
t1=[0 1 2 3 4 5 5 6 7 8 9 10 11 12 13 14 15 16 17 19 20 20 21 22];
g1=[0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 0];
plot (t1,g1)
grid on
xlabel('time')
ylabel('g(t)')
title('Input')
subplot(2,1,2)
plot (t,y(t))
grid on
xlabel('time')
ylabel('y(t)')
title('ODE system Response')
thanks a lot
I found the syntax called fplot

Connectez-vous pour commenter.

Community Treasure Hunt

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

Start Hunting!

Translated by