Mouad Sama
Mouad Sama

Reputation: 3

How to evaluate and plot symbolic variable in a symbolic function in MATLAB?

I want to create a symbolic function with three variables: x is a vector and s and m are scalars. Then I want to plot the function using m and s as 0 and 1, and x spanning the interval [-10, 10]. I tried the following:

syms x m s
%x=
y(x)=((1/(s*sqrt(2*pi)))*exp(-1/2*((x-m)/s)^2))
m=0
s=1
yx=subs(y)
y
yx
fplot(linspace(-10,10),yx)

The plot seems weird. Where is my mistake?

Upvotes: 0

Views: 1234

Answers (1)

gnovice
gnovice

Reputation: 125854

You're using the wrong syntax to call fplot. Just call it like so:

fplot(yx);

This will use the default x range of [-5 5]. If you want to change the x range, add a 2-element vector argument in the call to fplot, like so:

fplot(yx, [-10 10]);  % Plots over the range [-10 10]

When you put linspace(...) as the first argument, MATLAB appears to interpret it as if you're trying to use the 2-argument calling syntax fplot(funx, funy), which expects both the inputs to be parametric functions (which they aren't).

Upvotes: 1

Related Questions