how to stem an expression function in discrete manner as using fplot to evaluate expression function in continuous manner?

7 visualizaciones (últimos 30 días)
I can use fplot to plot an expression, which means I can plot the function without specify the range of dependent variable. For example, >>syms x; fplot(heaviside(x),[-4, 4]); It plots the continous function heaviside and show plots from range [-4 4]. Now, supposedly I want an discrete sample of such plot how do I do it ?
For example, I tried: >>syms x; stem(heaviside(x),[-4,4]); ==> but matlab cannot using stem function to evaluate the expression function.
I know that I can do: >> x=-10:10; stem(heaviside(x),[-4,4]); ==> matlab will plot this, but it is not what I want, I want it to be ploted in the discrete manner without specifying "x=-10:10". In other words, I want an function expression to be evaluated in the way that stem function does to an definite function. Or to say if there is a discrete plot/stem function for an expression function like fplot for continuous expression function?
Thank you very much!

Respuestas (1)

Walter Roberson
Walter Roberson el 17 de Mzo. de 2017
Editada: Walter Roberson el 17 de Mzo. de 2017
You can pass a function handle to fplot. You can use matlabFunction to create function handles from symbolic expressions.
However, not all symbolic expressions can be converted. If the expression makes use of a symbolic function that there is no corresponding numeric function for, such as piecewise, then it might not be able to do the conversion.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by