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));

 採用された回答

Walter Roberson
Walter Roberson 2017 年 5 月 9 日

1 投票

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 件のコメント

Sadon Alathba
Sadon Alathba 2017 年 5 月 9 日
Thanks Walter for providing a good answer. Guess I added the second derivative by mistake, and as always Thank You :)

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeMATLAB についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by