Matlab

Multiple Functions On the Same Graph

Multiple Functions On Same Graph:

In matlab we can draw multiple functions on the same graph by considering some basic colors.

Colors                        code

White                           w

Blue                              b

Cyan                             c

Black                            k

Green                           g

Magenta                       m

Yellow                          y

Red                                r

Let us consider a script for two polynomials.

g(x)= 4x4+3x3+2x2+2x+9

h(x)=4x3+9x+2

x=[-15:0.01:15];

g=4*x.^4 + 3* x.^3 + 2 * x.^2 + 2 * x + 9

h=4 * x.^3 + 9 * x + 2;

Plot(x, g, ‘k’, x, h, ‘r’)

When you run the file you will output as shown in below.

AXIS SETTING:

In order to provide minimum and maximum values for x and y axis by considering the axis command. With axis command allow us to set axis scale.

Syntax will be:

axis ([xmin  xmax  ymin  ymax])

FOR GENERATING SUBPLOT:

Subplot in matlab is used to divide the current figure and allow us to plot multiple figures in the m rows and n column.

Syntax for matlab

Subplot (m, n, p)

Let us consider a example for plotting

In order to plot the income in the top half of the figure and outgo in the bottom half of the figure,

      income = [3.2 4.1 5.0 5.6];
outgo = [2.5 4.0 3.35 4.9];
subplot(2,1,1); plot(income)
subplot(2,1,2); plot(outgo)

Below figure shows four subplot regions

The following combinations produce asymmetrical arrangements of subplots.

 subplot(2,2,[1 3])

subplot(2,2,2)

subplot(2,2,4)

Rajeshwari Chiluveru

Share
Published by
Rajeshwari Chiluveru

Recent Posts

Google Spam Update 2025: Impact, Recovery Guide & SpamBrain Explained

Google released a spam update on 26th of August 2025 and this is affecting a…

2 weeks ago

Google Experiments with Black Sitelink Colors instead of Blue

Google keeps on testing google search display all the time and this time we are…

1 year ago

What are Template Tags in WordPress? How to Use Template Tags

In wordpress if you are developing new or custom wordpress theme or wordpress plugin then…

2 years ago

Google Search Indexing Issues Started on 31st January to February 2024

If you are experiencing indexing issues of your website then you are not alone and…

2 years ago

Create QR Code for Pages & Post using Plugin in WordPress

On your wordpress website if you want to generate qr code for pages and posts…

2 years ago

Add Google Search Console HTML File Upload on WordPress

If you are trying to verify your WordPress website with google search console with html…

2 years ago