How to specify intervals of increasing, decreasing of a function in MATLAB
Hello, I want to specify intervals of increasing & decreasing of a function for a specific range; say -20-20. This is my code here:
clc, close, clear
syms x y real
dy=1-(4/x^2); x=~0; % This is the derivative of the function
% dy=(sin(x)-1)*(2*cos(x)+1); % (0<=x<=2*pi) % Code doesn’t work for this.
fplot(dy); hold on; axis([-5, 5, -5, 5]);
j=xline(0); set(j,’color’,’black’,’Linewidth’, 1.5)
k=yline(0); set(k,’color’,’black’,’Linewidth’, 1.5)
cp=solve(dy); % Finding critical points
y_cp=subs(dy,cp);
[~,idx] = unique(cp);
cp = cp(idx);
y_cp = y_cp(idx);
[num, den]=numden(dy); % Not a conventional way to find other critical points
cp2=solve(den==0);
disp(‘The critical points are:’)
for k =1:length(cp)
fprintf("(%.2f,%.2f)n",cp(k), y_cp(k))
plot(cp,y_cp,’*’, ‘color’, ‘black’);
end
for k =1:length(cp2)
fprintf("x = %.2f is a critical point, y is undefinedn",cp2(k))
end
% y is increasing if dy > 0, decreasing if dy < 0, if dy=0 it’s a critical point. Code below doesn’t work.
for i = -20:20
dy_sub_i=subs(dy,i);
end
if dy_sub_i>0
fprintf(‘f is increasing in %s-%s’, i(0), i);
elseif dy_sub_i<0
fprintf(‘f is decreasing in ‘);
endHello, I want to specify intervals of increasing & decreasing of a function for a specific range; say -20-20. This is my code here:
clc, close, clear
syms x y real
dy=1-(4/x^2); x=~0; % This is the derivative of the function
% dy=(sin(x)-1)*(2*cos(x)+1); % (0<=x<=2*pi) % Code doesn’t work for this.
fplot(dy); hold on; axis([-5, 5, -5, 5]);
j=xline(0); set(j,’color’,’black’,’Linewidth’, 1.5)
k=yline(0); set(k,’color’,’black’,’Linewidth’, 1.5)
cp=solve(dy); % Finding critical points
y_cp=subs(dy,cp);
[~,idx] = unique(cp);
cp = cp(idx);
y_cp = y_cp(idx);
[num, den]=numden(dy); % Not a conventional way to find other critical points
cp2=solve(den==0);
disp(‘The critical points are:’)
for k =1:length(cp)
fprintf("(%.2f,%.2f)n",cp(k), y_cp(k))
plot(cp,y_cp,’*’, ‘color’, ‘black’);
end
for k =1:length(cp2)
fprintf("x = %.2f is a critical point, y is undefinedn",cp2(k))
end
% y is increasing if dy > 0, decreasing if dy < 0, if dy=0 it’s a critical point. Code below doesn’t work.
for i = -20:20
dy_sub_i=subs(dy,i);
end
if dy_sub_i>0
fprintf(‘f is increasing in %s-%s’, i(0), i);
elseif dy_sub_i<0
fprintf(‘f is decreasing in ‘);
end Hello, I want to specify intervals of increasing & decreasing of a function for a specific range; say -20-20. This is my code here:
clc, close, clear
syms x y real
dy=1-(4/x^2); x=~0; % This is the derivative of the function
% dy=(sin(x)-1)*(2*cos(x)+1); % (0<=x<=2*pi) % Code doesn’t work for this.
fplot(dy); hold on; axis([-5, 5, -5, 5]);
j=xline(0); set(j,’color’,’black’,’Linewidth’, 1.5)
k=yline(0); set(k,’color’,’black’,’Linewidth’, 1.5)
cp=solve(dy); % Finding critical points
y_cp=subs(dy,cp);
[~,idx] = unique(cp);
cp = cp(idx);
y_cp = y_cp(idx);
[num, den]=numden(dy); % Not a conventional way to find other critical points
cp2=solve(den==0);
disp(‘The critical points are:’)
for k =1:length(cp)
fprintf("(%.2f,%.2f)n",cp(k), y_cp(k))
plot(cp,y_cp,’*’, ‘color’, ‘black’);
end
for k =1:length(cp2)
fprintf("x = %.2f is a critical point, y is undefinedn",cp2(k))
end
% y is increasing if dy > 0, decreasing if dy < 0, if dy=0 it’s a critical point. Code below doesn’t work.
for i = -20:20
dy_sub_i=subs(dy,i);
end
if dy_sub_i>0
fprintf(‘f is increasing in %s-%s’, i(0), i);
elseif dy_sub_i<0
fprintf(‘f is decreasing in ‘);
end for loop, fplot, fprintf MATLAB Answers — New Questions