Effacer les filtres
Effacer les filtres

Piecewise Function (Toolbox Doesn't Work)

4 vues (au cours des 30 derniers jours)
balla243
balla243 le 28 Jan 2024
Modifié(e) : balla243 le 28 Jan 2024
Hi,
When I try to create a piecewise function with the Symbolic Math Toolbox, it says unrecognized. I cleared the toolbox path cache and reset paths to default. I checked "which ~all <piecewise>" but it's like it doesn't exist.
After creating a piecewise function, I need to plot it discretely. It should look like this:
n2=-2:0.5:0;
f2 = @(n2) (0);
hold on
n=0:0.5:5;
f = @(n) (3*exp(-n).*sin(pi*n));
figure;
stem(n, f(n));
TIA
  2 commentaires
Dyuman Joshi
Dyuman Joshi le 28 Jan 2024
Do you have the Symbolic Math Toolbox installed?
Type "ver" in the command window and check the output.
balla243
balla243 le 28 Jan 2024
Yes, I installed it and I've confirmed w/ "ver."

Connectez-vous pour commenter.

Réponse acceptée

Matt J
Matt J le 28 Jan 2024
Modifié(e) : Matt J le 28 Jan 2024
Why bother with symbolic math? Why not just plot as below?
n=linspace(-2,5);
f = @(n) (3*exp(-n).*sin(pi*n)).*(n>=0);
plot(n,f(n),'b',n, 3*exp(-n),':r'); ylim([-3,3])
  2 commentaires
balla243
balla243 le 28 Jan 2024
Modifié(e) : balla243 le 28 Jan 2024
EDIT: Forgot to delete "n, 20*exp(-n),':r')" when using stem. Can you please explain how the function "starts" at zero? When I check w/ Desmos Graphing Calculator, there should be another x-intercept.
-----------------------------------------------------------------------------
I appreciate you showing me how to recreate a re-scaled version of the image that I provided. I hoped to use syms to plot as a discrete function and using "stem" gives the error "Incorrect number of inputs for property-value pairs."
n=linspace(-2,5);
f = @(n) (20*exp(-n).*sin(pi*n)).*(n>=0);
stem(n,f(n),'b',n, 20*exp(-n),':r');
Matt J
Matt J le 28 Jan 2024
Modifié(e) : Matt J le 28 Jan 2024
stem only allows you to plot one locus at a time. So, as a stem plot, you could do,
n=linspace(-2,5);
f = @(n) (20*exp(-n).*sin(pi*n)).*(n>=0);
stem(n,f(n),'b');hold on,
plot(n, 20*exp(-n),':r'); hold off
ylim([-20,20])

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Symbolic Math Toolbox dans Help Center et File Exchange

Produits


Version

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by