Download as pdf or txt
Download as pdf or txt
You are on page 1of 12

Lecture | 03

Solving the mathematical


formulas and equations
using script file in
MATLAB.

Lecture | 03
Solving the mathematical formulas and equations using script file in MATLAB:

1. Identify the input elements.


2. Operations of processing.
3. Output Device.

Lecture | 03
Solving the mathematical formulas and equations using script file in MATLAB:

1. Identify the input elements. It is the stage which the input variables
2. Operations of processing. are determined in the memory.
3. Output Device.
Using specific value(s) via the program’s
code or allowing the user to enter that
value(s) during the program is run in the
command window.

a=input('Enter the height: ');


b=input('Enter the Width: ');

Lecture | 03
Solving the mathematical formulas and equations using script file in MATLAB:

1. Identify the input elements. Performing the required mathematical


2. Operations of processing. and logical operations for the input
3. Output Device. variables that identify in the previous
stage or determining the relationships
between them.

Then assign the results to the output


variables
area=a*b;
per=2*(a+b);

Lecture | 03
Solving the mathematical formulas and equations using script file in MATLAB:

1. Identify the input elements. Determine the device of outputting the


2. Operations of processing. results by printing, scanning, or writing to
3. Output Device. a text file or word processor, etc
% Show output device:
disp('The value of rectangles area= '),disp(area)
disp('The value of rectangles perimeter= '),disp(per)

% Print output device:


fprintf('The value of rectangles area=%d\n',area)
fprintf('The value of rectangles perimeter=%d\n',per)

% Open a file for writing


fid=fopen('f.txt','w');
fprintf(fid,'The value of rectangles area=%d\n',area);
fprintf(fid,'The value of rectangles perimeter=%d\n',per);
Lecture | 03
% Show output device:
disp('The value of rectangles area= '),disp(area)
disp('The value of rectangles perimeter= '),disp(per)

% Print output device:


fprintf('The value of rectangles area=%d\n',area)
fprintf('The value of rectangles perimeter=%d\n',per)

% Open a file for writing


fid=fopen('f.txt','w');
fprintf(fid,'The value of rectangles area=%d\n',area);
fprintf(fid,'The value of rectangles perimeter=%d\n',per);
Solving the mathematical formulas and equations using script file in MATLAB:

1. Identify the input elements.


2. Operations of processing.
3. Output Device.

Lecture | 03
Examples: eg, Q1 & Q2
Homework: Q3 & Q4

Lecture | 03
eg: Using MATLAB to find the two variables of the general formula:

−𝑏 ± 𝑏 2 − 4𝑎𝑐
𝑥=
2𝑎

Lecture | 03
1- Identify the input elements.

2- Operations of processing.

3- Output Device.
Examples: Q1 & Q2 | Homework: Q3 & Q4

Q1> Compute using a script file in MATLAB the square & cubic of an inserted element?

Q2> Using MATLAB, compute the both formulas of the following?


1) 3x+y-5
2) -7x+4y+2

Q3> Using MATLAB, prove the Pythagors theorem?


a^2+b^2=c^2

Q4> Using MATLAB find the area and perimeter of the rectangle?
area=a*b
per=2(a+b)
Lecture | 03

You might also like