# Plotting a Piecewise Function

1 visualizzazione (ultimi 30 giorni)
Sazcl il 9 Gen 2022
Commentato: Sazcl il 9 Gen 2022
Hi everyone, I'm very new to MATLAB. I'm having a trouble with plotting a piecewise function.
Here is my piecewise function:
y(x)=if x<0, y=0
if x>0, y=1
z(x)=(1+(x-1).*exp(-x))*y(x)
I need to plot z(x) function. Here is my code:
x=-3:0.01:3;
syms x
y=piecewise(x<0,0, x>0,1);
z=(1+(x-1).*exp(-x))*y(x);
plot(z,x)
And this is the error that I got: Error using plot Data must be numeric, datetime, duration or an array convertible to double.
##### 0 CommentiMostra -2 commenti meno recentiNascondi -2 commenti meno recenti

Accedi per commentare.

### Risposta accettata

VBBV il 9 Gen 2022
Modificato: VBBV il 9 Gen 2022
syms x z(x)
y=piecewise(x<0,0, x>0,1);
z(x)=(1+(x-1).*exp(-x)).*y;
fplot(z,[-3 3])
Best wishes
##### 1 CommentoMostra -1 commenti meno recentiNascondi -1 commenti meno recenti
Sazcl il 9 Gen 2022
Thank you so much.

Accedi per commentare.

### Categorie

Scopri di più su Assumptions in Help Center e File Exchange

R2019a

### Community Treasure Hunt

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

Start Hunting!

Translated by