Im very new at Matlab and I can't seem to figure out this seemingly simple task. I have 3 functions f(x), g(x), and h(x) which are technically the same but formatted differently. What I need to do is print out 101 equally spaced values between [0.99,1.01] for each of these functions. Then I need to plot these values on the same graph. Does anyone know how to do this? I've never used Matlab before and I can't find instructions for doing this anywhere. Thanks in advance!
Asked
Active
Viewed 1,269 times
2 Answers
2
Here's a basic template you could follow:
n = 101; a = 0.99; b = 1.01;
step = (b - a)/(n - 1);
x = [a : step : b];
% NOTE: x is a vector containing the n numbers:
% x = [a, a + (b-a)/(n-1), ..., a + (n-1)(b-a)/(n-1) = b]
% Fill in your functions here.
f = sin(2*pi/0.01 * x) + 1;
g = sin(2*pi/0.01 * x) + 2;
h = sin(2*pi/0.01 * x) + 3;
plot(x,f, x,g, x,h)
Adriano
- 41,576
-
Thank you so much, this works perfectly and helps me understand how to use matlab so much more. Thanks! – zack Sep 15 '13 at 21:13
-
No problem! I'm just learning MATLAB myself this semester, and this question was good practice for me. =] – Adriano Sep 15 '13 at 21:17