hi, i need to run this code and plot it properly

clear all;
clc;
close all;
u=[2 0 1 5 1 7 4 3 3];
n=max(u);
m=mean(u);
syms x p;
p=1200;
y=@(x)(x*(p-3*x));
gy=ezplot(y);
hold on
grid on
df=diff(y(x),1);
xin=solve(y(x));
xint=[xin,zeros(length(xin),1)];
yin=[0,y(0)];
plot(xint(:,1),xint(:,2),'+');
plot(yin(:,1),yin(:,2),'+');
hold on
crit=solve(df);
critp=[crit,y(crit)];
plot(critp(:,1),critp(:,2))
hold on
dff=diff(y(x),2);
inf=solve(dff);
infp=[inf,y(inf)];
plot(infp(:,1),infp(:,2));

 Akzeptierte Antwort

Walter Roberson
Walter Roberson am 9 Mai 2017
Your function y(x) is a quadratic function.
The first derivative of y(x) is linear so it is possible to solve() that.
But the second derivative of a quadratic function is a constant. That constant is either equal to 0 or it is not equal to 0, so you cannot solve() the second derivative.
Also you have
inf=solve(dff);
which overwrites the normal inf() function in MATLAB which stands for infinity. Although MATLAB allows you to create a variable with the same name as the infinity function, doing that is quite confusing for the readers of your code. I have no idea what you are trying to determine at that point.

1 Kommentar

Thanks Walter for providing a good answer. Guess I added the second derivative by mistake, and as always Thank You :)

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu MATLAB finden Sie in Hilfe-Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by