how to write a plot for y=f(x) where y=3x^3+2 and x=[1:10:100] in matlab

To plot the function y=f(x) in Matlab, you can follow these steps:

  1. Define the function f(x) as y = 3*x.^3 + 2, where the .^ operator is used to perform element-wise power operation on each element in the array x.

  2. Create the array x using the colon operator, as x = [1:10:100].

  3. Call the plot function with the arguments plot(x, y) to plot the function.

  4. You may also want to add some labels, title, and grid to your plot for better readability. Here's the complete Matlab code snippet:

main.m
% Define function f(x) as y = 3x^3 + 2
x = [1:10:100];
y = 3*x.^3 + 2;

% Plot the function y=f(x)
plot(x, y);

% Add some labels and grid to the plot
xlabel('x');
ylabel('y');
title('Plot of y = 3x^3 + 2');
grid on;
217 chars
13 lines

This will generate a plot like this:

Matlab plot of y=f(x)

gistlibby LogSnag