- 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 (최근 30일)
이전 댓글 표시
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
답변 (1개)
Akshat
2024년 9월 4일
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
참고 항목
카테고리
Help Center 및 File Exchange에서 Develop Apps Using App Designer에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!