How would you define a sine function with the only argument x and parameters a(beginning of interval) b( end of interval) and m ( the number of complete Periods) Where the parameters are in the function definition?
2 views (last 30 days)
Show older comments
Alyssa Cleveland
on 5 Feb 2016
Answered: Image Analyst
on 5 Feb 2016
For example I have a parameters a=2 b=6 and m=3. I am not sure how to set up the function with the parameters are in the function definition. The one way I have it set up is f=@(x,a,b,m)sin(x); There is another way to do this where the function starts as f=@(x) where a, b, and m are in the function.
0 Comments
Accepted Answer
Image Analyst
on 5 Feb 2016
Try this:
function test1
y = rand(1,M);
x = rand(1,M);
a=2;
b=6;
m=3;
PlotSin(a, b, m);
%==============================================
function PlotSin(a,b,m)
numSamples = 200; % Whatever you want.
x = linspace(a, b, numSamples);
% period * m = (b-a), so
period = abs(b-a) / m;
y = sin(2 .* pi * x / period);
plot(x, y, 'bo-', 'LineWidth', 2);
grid on;
fontSize = 24;
xlabel('x', 'FontSize', fontSize);
ylabel('y', 'FontSize', fontSize);
caption = sprintf('sin wave with %d periods between %.1f and %.1f', m, a, b);
title(caption, 'FontSize', fontSize);
% Set up figure properties:
% Enlarge figure to full screen.
set(gcf, 'Units', 'Normalized', 'OuterPosition', [0 0 1 1]);
% Get rid of tool bar and pulldown menus that are along top of figure.
set(gcf, 'Toolbar', 'none', 'Menu', 'none');
% Give a name to the title bar.
set(gcf, 'Name', 'Demo by ImageAnalyst', 'NumberTitle', 'Off')
%
0 Comments
More Answers (0)
See Also
Categories
Find more on Get Started with Statistics and Machine Learning Toolbox in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!