- In order to get a plot, you need two arrays, with the values containing at the corresponding time stamps.
- In the function definition above the code given by you, you haven't specified anything about "y". I am going to assume that the function is only "g" and it takes different functions at different time stamps.
- The time stamps that you are taking, are [0,1,2,3]. This is a very big time gap, and the curve will not be smooth, rather it will just have 4 points. Hence, I have changed the step size to 0.1, giving us 40 points to work with, making the curve a little more smooth. This way the points will be [0,0.1,0.2.....2.8,2.9,3].
program to display the curve of the function
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
program pour afficher la courbe de la fonction suivant
g=2t+2 y[0,2[
g=2 cos(4pi*t) t=[2,3]
for t=[0:3];
if t<2
g=2*t+2;
plot(g)
else t>=2
y=2*cos(4*pi*t);
plot(y)
end
end
0 commentaires
Réponses (1)
Akshat
le 4 Sep 2024
Hi Adam,
I see you are trying to plot the "g" when "t" is lesser than 2, and "y" when "t" is greater than or equal to 2.
These are the points I think you are missing:
Here is the code with changes that I suggested:
t = 0:0.1:3; % Use a finer step for smoother plot
g = zeros(size(t));
for i = 1:length(t)
if t(i) < 2
g(i) = 2*t(i) + 2;
else
g(i) = 2*cos(4*pi*t(i));
end
end
figure;
plot(t, g, 'LineWidth', 2);
xlabel('t');
ylabel('g(t)');
title('Piecewise Function Plot');
grid on;
0 commentaires
Voir également
Catégories
En savoir plus sur Develop Apps Using App Designer dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!