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

EXPERIMENT 3

Conditional Functions:
Logical Expressions, Boolean Functions, IF Function, Creating a Quadratic
Equation Solver, Table VLOOKUP Function, AND, OR and XOR function.
A logical expression is a statement that can either be true or false. For example, a < b is a
logical expression. It can be true or false depending on what values of a and b are given.

Logical expressions (also called Boolean expressions) are the result of applying logical
(Boolean) operators to relational or arithmetic expressions.

 A conditional function performs an action or calculation based on a test


of data using an IF statement.
 Use a conditional function to provide a TRUE or FALSE result to
highlight or filter out data based on specific criteria.
 Conditional functions can be used with any data type.
 Testing whether conditions are true or false and making logical
comparisons between expressions are common to many tasks.
 You can use the AND, OR, NOT, and IF functions to create conditional
formulas.
 A logical expression is a statement that can either be true or false.
 For example, a < b is a logical expression. It can be true or false
depending on what values of a and b are given. Note that this differs from
a mathematical expression which denotes a truth statement.
 Logical expressions (also called Boolean expressions) are the result of
applying logical (Boolean) operators to relational or arithmetic
expressions.
 The result of an operation has two possible states: true or false.
 Logical expressions are considered false when equal to 0, and are
considered true when nonzero.

Example IF Function:
Category Budget Actual Status
Airfare 600 525
food 350 296
Entertainment 250 1500
Output:

Category Budget Actual Status


Airfare 600 525 within budget
food 350 296 within budget
Entertainment 250 1500 over budget

Type = in Status of airfare Click fx insert function dialog box opens


Then click on IF function press ok
In logical test Select 525 number type < select 600 number
In Value if_true “within budget”
In Value_ if_false “overbuget”
Press ok, and then drag all values displays.

Creating a Quadratic Equation Solver: ax2+bx+c=0

X= (-b +/-SQRT(b^2-4ac))/2a

Example: a=6, b=8, c=2


a 6
b 8
c 2

x1 -0.33
x2 -1

In column X1
Type = (-E8+SQRT (E8^2-4*E7*E9))/ (2*E7) x1 value displays

Similarly In column X2

Type = (-E8-SQRT(E8^2-4*E7*E9))/(2*E7) x2 value displays

OUTPUT: X1=-0.33
X2=-1
a 6
b 8
c 2

x1 -0.33
x2 -1

VLOOKUP Function:
The VLOOKUP function is a premade function in Excel, which allows searches
across columns.
order No product unit price quantity
10247 apple 14 12
10249 oranges 10 10
10250 banana 34 5
10251 pears 18 9
10252 grapes 42 40

=VLOOKUP(A5,A2:B6,2,FALSE) OUTPUT PEARS


=VLOOKUP(A5,A2:B6,1,FALSE) OUTPUT 10251
Type =VLOOKUP (select 10251, select all 10247(column1) to grapes
(cloumn2),type 2,type false) press enter output results. Similarly try one more.
OUTPUT:
unit
order No product quantity
price
10247 apple 14 12 pears

10249 oranges 10 10

10250 banana 34 5
10251 pears 18 9
10252 grapes 42 40

10249

And Function:
=IF(AND(E6>=0,E6<=40),"Fail",IF(AND(E6>=40,E6<=60),"Pass",I
F(AND(E6>=60,E6<=100),"Distinction","Inalid")))
OR and XOR function:
 Now the OR operator is saying, if the first argument or the second
argument are true, then the result is true.
Place cursor on any cell then type below conditions, result true or false displays.
=OR(1>2) FALSE

=OR(1>2,2>3) FALSE

=OR(2<3) TRUE

=OR(1<2,2<3) TRUE

 Lastly, the XOR (exclusive OR) operator is saying, if input is true, then
the result is true, but if both inputs are true, then the result is false.

=XOR (1>0,2<1) TRUE

=XOR (1>0,2>1) FALSE

=XOR (1<0,2<1) FALSE


EXPERIMENT 4
Regression Analysis:
Trendline, Slope and Intercept:
A trend line indicates a linear relationship. The equation for a linear
relationship is y = mx + b, where x is the independent variable, y is
the dependent variable, m is the slope of the line, and b is the y-
intercept.
X Y
1 10
2 14
3 18
4 22
5 26

select all X & Y values, go to Insert then go scatter and select scatter with
straight line markers, the below graph displays.

700

600

500

400
Series1
300

200

100

0
0 1 2 3 4 5 6

Then on straight line click right button of mouse, go to add Trend line, select
Linear then select display equation on chart then below graph displays.

Where y=4x+6 reveals m=slope=4 Intercept=6


700

600

500

400
y = 50x + 125 Series1
300 Linear (Series1)

200

100

0
0 1 2 3 4 5 6

Click on any cell of excel sheet type =slope(select all values of Y column then
put comma then select all values of X column) then atlast press enter the answer
of slope 4 displays

Similarly repeat the same procedure as above to get Intercept value 6

Interpolation and Forecast


Linear interpolation in Excel means forecasting or guessing the next value of
any certain variable given on the current data. Here, we create a straight line
that connects two values and estimates the future value. In Excel, we use a
FORECAST function and a LOOKUP function to do a linear interpolation.

Y=y1+(X-X1) * (Y2-Y1)/(X2-X1) where X is independent variable take for


example 83(0F)

Temperature (0F)[x values] People at beach [y values]


30 18
40 25
50 45
60 57
70 78
80(X1) 92(Y1)
90(X2) 106(Y2)
100 122

Keep cursor anywhere and type interpolation then below formula

Interpolation FORMULA=B6+(B13-A6)*((B7-B6)/(A7-A6))

Forecast=FORECAST(B13,B1:B8,A1:A8)
Note B13 means select X value

B1:B8 means select all Y values

A1:A8 means select all X values

PRESS ENTER ANSWER DISPLAYS

Interpolation =96.2

Forecast= 95.7

The LINEST Function:


The LINEST function calculates the statistics for a line by using the "least
squares" method to calculate a straight line that best fits your data, and then
returns an array that describes the line.

X Y
1 2.94
2 5.41
3 7.12
4 9.08
5 11.32
6 13.56
Select both X and Y values leaving X and y

Go to insert command then scatter then scatter with only markers graph displays

Right click on the any scatter point of graph add TREADLINE then select
Linear then put right mark on display equation on chart then display R 2 value on
chart.

On any cell try this formula below

=LINEST (D6:D11, C6:C11, FALSE, TRUE) first select all y values then x
values

Answer displays as 2.3011

Multilinear Regression:
Multiple linear regression is a regression model that estimates the relationship
between a quantitative dependent variable and two or more independent
variables using a straight line.

To add data analytics to excel software if it is not their:

File , options, add-inns , manage go, analysis tool pack tick mark then ok then
data analytics will be added at top

X Y
1 2.94
2 5.41
3 7.12
4 9.08
5 11.32
6 13.56
Go to data then data analytics then select regression press Ok

Select Y range values then select X values range

Tick labels, select new worksheet ply press OK then the below results come

SUMMARY
OUTPUT

Regression Statistics
Multiple R 0.998967914
R Square 0.997936893
Adjusted R Square 0.997421116
Standard Error 0.197788969
Observations 6

ANOVA
Significance
df SS MS F F
Regression 1 75.69120143 75.69120143 1934.823111 1.59725E-06
Residual 4 0.156481905 0.039120476
Total 5 75.84768333

Standard
Coefficients Error t Stat P-value Lower 95% Upper 95% L
Intercept 0.959333333 0.184131509 5.210044371 0.006471426 0.448102306 1.470564361 0
X 2.079714286 0.047280607 43.98662422 1.59725E-06 1.948442276 2.210986295 1

age duration distance price


61 16 3.2 22.3
24 4 1.5 12.5
47 29 5.1 11.5
32 33 5.8 8.5
23 14 2.3 32.6
82 30 6.1 23.5
57 56 12 25.5
36 11 1.9 15.3
SUMMARY
OUTPUT

Regression Statistics
Multiple R 0.3175
R Square 0.1008
Adjusted R Square -0.5736
Standard Error 10.3960
Observations 8

ANOVA
Significance
df SS MS F F
Regression 3 48.47489 16.1583 0.149509 0.924804
Residual 4 432.3039 108.076
Total 7 480.7788

Standard Upper Lower U


Coefficients Error t Stat P-value Lower 95% 95% 95.0% 9
Intercept 15.71913 10.0141 1.5697 0.19157 -12.0845 43.52273 -12.0845 43
age 0.07676 0.222433 0.345093 0.747407 -0.54081 0.694332 -0.54081 0.
duration -0.57777 1.38257 -0.4179 0.69748 -4.4164 3.260855 -4.4164 3.
distance 2.893676 6.726315 0.430202 0.689213 -15.7816 21.56892 -15.7816 21

Polynomial Fit Functions:

X Y
1 0.0
2 0.8
3 -10.2
4 -31.8
5 -55.6
6 -66.0
7 -40.2
8 51.8
9 247.2
10 590.4
Fit a polynomial of degree 4 to the 5 points. In general, for n points, you can fit
a polynomial of degree n-1 to exactly pass through the points.

Go to insert command then scatter then scatter with only markers graph displays

Right click on the any scatter point of graph add TREADLINE then select
POLYNOMIAL select degree 4 then put right mark on display equation on
chart

700.0

600.0

500.0
y = 0.3x4 - 2.8x3 + 3.4x2 + 5.7x - 6.6
400.0
Series1
300.0
Poly. (Series1)
200.0

100.0

0.0
0 2 4 6 8 10 12
-100.0

Keep cursor on any cell type below

=LINEST (C3:C12, B3:B12^ {1,2,3,4}) answer displays as 0.3

Note: C3:C12 means select all Y values B3:B12 means select all X values

Then select adjacent four cells of 0.3 Press f2 simultaneously press control+shift
and enter displays

Residuals Plot: A residual plot is a type of plot that displays the fitted
values against the residual values for a regression model.

NOTE: Take the same example of polynomial fit function


Go to data then data analytics then select regression press Ok

Select Y range values then select X values range


Tick labels, select new worksheet ply press

Select residuals and residual plot

OK then the below results come

1 Residual Plot
400
Residuals

200

0
0 2 4 6 8 10 12
-200
1

Slope and tangent:


The slope is defined as the ratio of the difference in y coordinate to the
difference in x coordinate. It is represented by the following formula:

m = (y⁠⁠2 – y⁠⁠1) / (x⁠⁠2 – x⁠⁠1)

The tangent line is the line that touches a curve at a point.

y= mx + c where c is some constant

1 70
2 60
3 50
4 40
5 30
6 20
7 10
8 5
9 3
10 2

select all X & Y values, go to Insert then go scatter and select scatter with
straight line markers, the below graph displays
Then on straight line click right button of mouse, go to add Trend line, select
Linear then select display equation on chart then below graph displays.
80
70
60 y = -8.097x + 73.533
50
40 Series1
30
20 Linear (Series1)
10
0
-10 0 5 10 15
-20

Analysis Tool Pack: The Analysis Tool Pack is an Excel add-in


program that provides data analysis tools for financial, statistical and
engineering data analysis.

Random 1 random 2
10 16
20 22
30 55
40 66
50 78

Go to data then data analysis select correlation press ok in input range


select both columns select columns select labels in first row output range
select any cell

Go to data analysis then select moving average press ok select for input
range select second row values only 16 to 78 select output range any cell
tick chart output press ok graph displays as below

Moving Average
100
Value

50
Actual
0 Forecast
1 2 3 4 5
Data Point

You might also like