Plot the following equation using MATLAB

Plot the following equation using matlab
Plot Y=3x³-26x+10 -2<=x<=4
Interval and its first and second derivative , all in the same plot

2 Comments

What have you tried for this home work?
Yes I had tried
syms t
Y=3x³-26x+10;
X = -2;
X=4
ezplot(x, y)

Sign in to comment.

Answers (1)

Y=3x³-26x+10
MATLAB has no implied multiplication anywhere. You cannot use, for example, 26x and have that be understood. You need to put in explicit multiplication.
The main multiplication operator in MATLAB is the .* operator, which is element-by-element multiplication. MATLAB also has the * operator, which is primarily intended for algebraic matrix multiplication -- but the forms ARRAY*SCALAR and SCALAR*ARRAY are both understood instead of having to use ARRAY.*SCALAR or SCALAR.*ARRAY
MATLAB does not understand superscript ³ or ² or the like as indicating exponentiation. Instead, you need to use a power operator. The main power operator in MATLAB is the .^ operator, which is element-by-element power. MATLAB also has the ^ operator, which is primarily intended for algebraic matrix power.
Now, when you are doing symbolic work, the derivative operator is named diff
Putting these together:
range = [-1 2];
syms x
Y = 2.*x.^4 - 5.*x.^3 + sin(x)
Y = 
dY = diff(Y);
d2Y = diff(dY);
fplot([Y, dY, d2Y], range)

Asked:

on 2 Nov 2020

Moved:

on 26 Feb 2025

Community Treasure Hunt

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

Start Hunting!