plot a mathmatical function

1 view (last 30 days)
Roger Nadal
Roger Nadal on 25 Nov 2019
Commented: Roger Nadal on 26 Nov 2019
function is called that will plot a mathematical function in one variable and in range 0 to 10 and function should recive input vector of integer and it has n length even. for example func([100,1500,3000]) will plot that number of points
Roger Nadal
Roger Nadal on 25 Nov 2019
Edited: Roger Nadal on 25 Nov 2019
Three different plots and has to give input mathematical expression for example sin(x)+x

Sign in to comment.

Answers (2)

Nicolas Douillet
Nicolas Douillet on 25 Nov 2019
Perhaps you should have a look at linspace.
u = linspace(1500,3000,16); % since there are 16 values between 1500 and 3000 with a sampling step of 100
I am not sure this is what you want to do, since your question is not so clear to me.
Hope this could help you anyway.

Walter Roberson
Walter Roberson on 25 Nov 2019
funstr = input('Enter expression in variable x ', 's');
fun = str2func(vectorize(funstr));
x = linspace(0,1,NumberOfPoints);
y = fun(x);
plot(x, y);
Now generalize this slightly to support multiple plots.
Roger Nadal
Roger Nadal on 26 Nov 2019
I didn’t understand?

Sign in to comment.


Find more on Elementary Math 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!

Translated by