Help Plotting Piecewise functions

I need help plotting the following piecewise function. I attatched the question.
This is what I have so far:
syms x
y = piecewise(0<=x<=3, 4*x^1/3, 3<x<=6, pi^x+e) % this is the line that is saying there is an error.
fplot(y)

Antworten (2)

Walter Roberson
Walter Roberson am 1 Sep. 2019

1 Stimme

Chaining equalities like that is only supported in very recent MATLAB. Also you are using the wrong exponent:
y = piecewise(0<=x & x<=3, 4*x^1/3, 3<x & x<=6, pi^(x+e))
If e is intended to be the base of the natural logs then chances are you are going to need to define e as e is not built-in constant in MATLAB. e = exp(1);

9 Kommentare

syms x
y = piecewise(0<=x & x<=3, 4*x^1/3, 3<x & x<=6, pi^(x+2.71828183))
fplot(y,'c')
So this?
y = piecewise(0<=x & x<=3, 4*x^1/3, 3<x & x<=6, pi^(x+exp(1)))
Question: what is the value of the function for negative x or x > 6 ?
Brianna Selles
Brianna Selles am 1 Sep. 2019
222.JPG
It is pi^x+e
Brianna Selles
Brianna Selles am 1 Sep. 2019
I'm not quite sure, actually where you're getting that value from. I attatched a picture of the question.222.JPG
Walter Roberson
Walter Roberson am 1 Sep. 2019
No. Look carefully at the second equation. The x + e is all the same font size and is all raised higher than the pi. . If it were pi^x+e then it would have been
Brianna Selles
Brianna Selles am 1 Sep. 2019
Yes!H ow do we raise e as an exponet?
syms x
e = exp(1)
y = piecewise(0<=x & x<=3, 4*x^1/3, 3<x & x<=6, pi^x^exp(1))
fplot(y,'c')
syms x
e = exp(1)
y = piecewise(0<=x & x<=3, 4*x^1/3, 3<x & x<=6, pi^(x+e))
fplot(y,'c')

Melden Sie sich an, um zu kommentieren.

madhan ravi
madhan ravi am 1 Sep. 2019
Bearbeitet: madhan ravi am 1 Sep. 2019

0 Stimmen

You are almost there , change e to exp()
syms x
y = piecewise(0<=x<=3, 4*x^1/3, 3<x<=6, pi^(x+e)) % Note the parentheses around pi
fplot(y,'c') % change this line
doc fplot % to see more examples

Gefragt:

am 1 Sep. 2019

Kommentiert:

am 1 Sep. 2019

Community Treasure Hunt

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

Start Hunting!

Translated by