Ticker

6/recent/ticker-posts

How to plot successive (positive) powers of x in MATLAB?

Question:

How to plot successive (positive) powers of x in MATLAB?

Answer:

The successive plots of x can be done by following the steps below:

  • Create and anaonymous function of x.
  • Create an array of positive numbers n from 1 to 10.
  • Plot anonymous function in using MATLAB built-in command "fplot".
  • As for every n in the array, graphs are generated. Legends on graph plot can be shown using string and LATEX interpreter.
  • Define the bounds of graph plot in x-axis and y-axis using MATLAB built-in commands "xlim" and "ylim"
  • clear all; clc;close all;
    n = 1:10;
    figure(1);
    f = @(x) x.^n;
    fplot(f);
    hold on;
    legend("$x^{"+n+"}$", 'interpreter','latex','Location','Best')
    xlim([-10 10])
    ylim([-100 100])
    grid on;

    OUTPUT

    Post a Comment

    0 Comments