0% found this document useful (0 votes)
42 views4 pages

Draw Mathematical Equations Using MATLAB

This document discusses how to draw mathematical equations using MATLAB. It provides examples of plotting simple functions like y=x, sin(x), and cos(x). It also demonstrates how to set colors on graphs and provides color codes. Finally, it shows an example of plotting two polynomial functions f(x) and g(x) in red and green colors.

Uploaded by

Henwa Mostafa
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
42 views4 pages

Draw Mathematical Equations Using MATLAB

This document discusses how to draw mathematical equations using MATLAB. It provides examples of plotting simple functions like y=x, sin(x), and cos(x). It also demonstrates how to set colors on graphs and provides color codes. Finally, it shows an example of plotting two polynomial functions f(x) and g(x) in red and green colors.

Uploaded by

Henwa Mostafa
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Draw mathematical equations using MATLAB

Presented BY –
Mohamed Abdullah Hassan

Doctor: Prof Tarek Haweel


Eng : Manar.m.salah
 Step to solve mathematical
To plot the graph of a function, you need to take the following steps −
1. Define x, by specifying the range of values for the variable x, for
which the function is to be plotted
2. Define the function, y = f(x)
3. Call the plot command, as plot(x, y)

 Example
x = [0:5:100];
y = x;
plot(x, y)

 Example
x = [0 : 0.01: 10];
y = sin(x);
g = cos(x);
plot(x, y, x, g, '.-'), legend('Sin(x)', 'Cos(x)')
 Setting Colors on Graph
MATLAB provides eight basic color options for drawing graphs. The following
table shows the colors and their codes −

Code Color

w White

k Black

b Blue

r Red

c Cyan

g Green

m Magenta

y Yellow
 Example

Let us draw the graph of two polynomials


 f(x) = 3x4 + 2x3+ 7x2 + 2x + 9 and
 g(x) = 5x3 + 9x + 2
Create a script file and type the following code −
x = [-10 : 0.01: 10];
y = 3*x.^4 + 2 * x.^3 + 7 * x.^2 + 2 * x + 9;
g = 5 * x.^3 + 9 * x + 2;
plot(x, y, 'r', x, g, 'g')

You might also like