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

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

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 MATLAB에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by