draw the graph of y=x^3-5x+1 for -5<x<5 and find y(10). in matlab

main.m
% Define the function
x = linspace(-5, 5, 1000);
y = x.^3 - 5*x + 1;

% Plotting the graph
plot(x, y)
xlabel('x')
ylabel('y')
title('Graph of y = x^3 - 5x + 1')

% Calculate y(10)
y_at_10 = 10^3 - 5*10 + 1;
disp(['y(10) = ', num2str(y_at_10)]);
245 chars
14 lines

related categories

gistlibby LogSnag