SlideShare a Scribd company logo
CS110: Models of Computing
Lecture 6
V. Kamakoti
14th January 2008
Today’s Lecture Contents

• Solving Quadratic Equations
• Given ax2 + bx + c = 0
• The roots are
• (-b + SQRT(b2 - 4ac))/2a
• (-b - SQRT(b2 - 4ac))/2a

• New things
•
•
•
•

Check if ‘a’ is 0
Check if ‘b’ is 0
Check if discriminant is < 0
Calculate SQRT
Calculate SQRT
• Input a double precision float and get a
double precision float as output
• The function “sqrt” is in <math.h> like how
“printf” is in <stdio.h>
• There is another function “sqrtl” also - find out
what it does?
• Use “Manual pages” in Unix
– Type the command “man sqrt” and you shall get
the details.
The Program
#include <stdio.h>
#include <math.h>
main() {
double a,b,c,DISC,R1,R2;
printf(“Enter a ?n”);
scanf(“%f”,&a); //Similarly for b and c
The Program
if (a == 0) {
printf(“The equation is not Quadratic n”);
if (b == 0)
printf(“No equation at alln”);
else
printf(“Root is %fn”, -c/b);
}
else
Program
{
DISC = b*b - 4*a*c; //Operator Precedence
if (DISC < 0)
{
printf(“No real solution existsn”);
}
else
{
//Paranthesis to handle precedence
R1 = (-b + sqrt(DISC))/(2*a));
R2 = (-b - sqrt(DISC))/(2*a));
//Print the roots
}
}
}
Polynomial Multiplication
• Input: Coefficients of two polynomials
P1 and P2 of degree 5
• Output: Coefficients of the polynomial,
which is the product of P1 and P2.
• Do not forget: There are Twelve Inputs
and Eleven Outputs
Polynomial multiplication
• (a1x + a0 ) (b1x + b0 )
– a1b1x2 + (a0b1 +a1b0 ) x + a0b0

• The coefficient of xk is sum of aibj’s such that i
+j=k
• In the program you have A0, A1,… A5 and
B0, B1,…, B5 for the coefficients of the input
polynomials and C0, C1, …., C10 for the
coefficients of the output polynomial.
For your problem
•
•
•
•
•
•

C0 = A0 * B0;
C1 = A0*B1 + B1*A0
…….
C8 = A3*B5 + A4*B4 + A5*B3
C9 = A4*B5 + B4*A5
C10 = A5 * B5
The problem
• Suppose there are n = 2k persons, each with
a certain item of information. In each step,
each person can communicate with another
person and share all the information he or
she knows (including information learned in
previous steps). A person cannot
communicate with more than one person in
any step. Design a communication (gossip)
pattern such that after log2n (= k) steps,
everyone knows everything.
Solution
• Numbering problem
– Number “N” people using integers 0 to N-1.
– N = 2k
– Group pairs of two - Number each 0,1
– Group pairs of these and prefix 0 to
numbers in one pair and prefix 1 to
numbers in the other pair.
– Repeat till only one group exist
Solution

0

0

0

0

0

0

0

0
Solution - Step 1

0

1

0

1

0

Groups of two

1

0

1
Solution - Step 2

00

01

10

11

00

Groups of four

01

10

11
Solution - Step 3

000

001

010

011

100

Groups of eight

101

110

111
Gossip - Step 1

0

1

0

1

0

Groups of two

1

0

1
Gossip - Step 2

00

01

10

11

00

Groups of four

01

10

11
Gossip - Step 3

000

001

010

011

100

101

110

Groups of eight - k-bits for n = 2k

111
Solution at a glance - Step 1

000

001

010

011

100

101

110

111
Solution at a glance - Step 2

000

001

010

011

100

101

110

111
Solution at a glance - Step 3

000

001

010

011

100

101

110

111
Creative Question - 3
• You are given a BLACK BOX - nothing is
known what is inside it - but it does the
following for you
– Give a sequence of n real numbers and an integer
k, the box will output “yes” or “no” indicating
whether there is a subset of the numbers whose
sum is exactly “k”. It will not tell you the subset.
– Use this black box to find the subset whose sum is
“k”, if it exists.
– You are allowed to use the black box exactly “n”
times, where “n” is the length of the sequence.
Example
(1.3,.7,2.5,1.7) and
k=3

Yes

The problem is using the above box exactly four times you
Should find out the subset that adds to 3, namely (1.3,1.7)
Example
(1.3,.7,2.5,1.7) and
k=3

Yes

All elements distinct
Remove an element and ask if it solves
Yes: element not in subset
No: element is in the subset
Example
(1.5,2,1.5,1.5) and
k=5

Yes

All elements not distinct
Thank You

More Related Content

What's hot

Octal and Hexadecimal Numbering Systems
Octal and Hexadecimal Numbering SystemsOctal and Hexadecimal Numbering Systems
Octal and Hexadecimal Numbering Systems
Leo Hernandez
 
Okkkkk
OkkkkkOkkkkk
Number systems
Number systemsNumber systems
Number systems
Mustafa Salah
 
numbers system
numbers systemnumbers system
numbers system
Shehrevar Davierwala
 
Binary numbersystem
Binary numbersystemBinary numbersystem
Binary numbersystem
Shehrevar Davierwala
 
Mat lab
Mat labMat lab
Matlab plotting
Matlab plottingMatlab plotting
Matlab plotting
pramodkumar1804
 
Chapter 07 Digital Alrithmetic and Arithmetic Circuits
Chapter 07 Digital Alrithmetic and Arithmetic CircuitsChapter 07 Digital Alrithmetic and Arithmetic Circuits
Chapter 07 Digital Alrithmetic and Arithmetic Circuits
SSE_AndyLi
 
Number system
Number system Number system
Number system
BPGCW
 
01.number systems
01.number systems01.number systems
01.number systems
Sripati Mahapatra
 
Number system....
Number system....Number system....
Number system....
mshoaib15
 
B.sc cs-ii -u-1.1 digital logic circuits, digital component floting and fixed...
B.sc cs-ii -u-1.1 digital logic circuits, digital component floting and fixed...B.sc cs-ii -u-1.1 digital logic circuits, digital component floting and fixed...
B.sc cs-ii -u-1.1 digital logic circuits, digital component floting and fixed...
Rai University
 
Number systems
Number systemsNumber systems
Number Systems
Number SystemsNumber Systems
Number Systems
student
 
number system
number systemnumber system
number system
Unsa Shakir
 
Digital differential analyzer
Digital differential analyzerDigital differential analyzer
Digital differential analyzer
Sajid Hasan
 
Lec 02
Lec 02Lec 02
Lec 02
Syed Haider
 
Bca 2nd sem u-1.1 digital logic circuits, digital component floting and fixed...
Bca 2nd sem u-1.1 digital logic circuits, digital component floting and fixed...Bca 2nd sem u-1.1 digital logic circuits, digital component floting and fixed...
Bca 2nd sem u-1.1 digital logic circuits, digital component floting and fixed...
Rai University
 
IME 2015 - fechada
IME 2015 - fechadaIME 2015 - fechada
IME 2015 - fechada
KalculosOnline
 
Number system computer fundamental
 Number  system computer fundamental  Number  system computer fundamental
Number system computer fundamental
Aman anand kumar
 

What's hot (20)

Octal and Hexadecimal Numbering Systems
Octal and Hexadecimal Numbering SystemsOctal and Hexadecimal Numbering Systems
Octal and Hexadecimal Numbering Systems
 
Okkkkk
OkkkkkOkkkkk
Okkkkk
 
Number systems
Number systemsNumber systems
Number systems
 
numbers system
numbers systemnumbers system
numbers system
 
Binary numbersystem
Binary numbersystemBinary numbersystem
Binary numbersystem
 
Mat lab
Mat labMat lab
Mat lab
 
Matlab plotting
Matlab plottingMatlab plotting
Matlab plotting
 
Chapter 07 Digital Alrithmetic and Arithmetic Circuits
Chapter 07 Digital Alrithmetic and Arithmetic CircuitsChapter 07 Digital Alrithmetic and Arithmetic Circuits
Chapter 07 Digital Alrithmetic and Arithmetic Circuits
 
Number system
Number system Number system
Number system
 
01.number systems
01.number systems01.number systems
01.number systems
 
Number system....
Number system....Number system....
Number system....
 
B.sc cs-ii -u-1.1 digital logic circuits, digital component floting and fixed...
B.sc cs-ii -u-1.1 digital logic circuits, digital component floting and fixed...B.sc cs-ii -u-1.1 digital logic circuits, digital component floting and fixed...
B.sc cs-ii -u-1.1 digital logic circuits, digital component floting and fixed...
 
Number systems
Number systemsNumber systems
Number systems
 
Number Systems
Number SystemsNumber Systems
Number Systems
 
number system
number systemnumber system
number system
 
Digital differential analyzer
Digital differential analyzerDigital differential analyzer
Digital differential analyzer
 
Lec 02
Lec 02Lec 02
Lec 02
 
Bca 2nd sem u-1.1 digital logic circuits, digital component floting and fixed...
Bca 2nd sem u-1.1 digital logic circuits, digital component floting and fixed...Bca 2nd sem u-1.1 digital logic circuits, digital component floting and fixed...
Bca 2nd sem u-1.1 digital logic circuits, digital component floting and fixed...
 
IME 2015 - fechada
IME 2015 - fechadaIME 2015 - fechada
IME 2015 - fechada
 
Number system computer fundamental
 Number  system computer fundamental  Number  system computer fundamental
Number system computer fundamental
 

Similar to Lec06-CS110 Computational Engineering

UNIT-1_CSA.pdf
UNIT-1_CSA.pdfUNIT-1_CSA.pdf
UNIT-1_CSA.pdf
ShabbeerBasha8
 
3306565.ppt
3306565.ppt3306565.ppt
3306565.ppt
JP Chicano
 
03_NumberSystems.pdf
03_NumberSystems.pdf03_NumberSystems.pdf
03_NumberSystems.pdf
vijayapraba1
 
Digital logic
Digital logicDigital logic
Digital logic
Md Shohel Rana
 
boolean algebra and logic simplification
boolean algebra and logic simplificationboolean algebra and logic simplification
boolean algebra and logic simplification
Unsa Shakir
 
Digital-Logic40124sequential circuits logic gatepptx
Digital-Logic40124sequential circuits logic gatepptxDigital-Logic40124sequential circuits logic gatepptx
Digital-Logic40124sequential circuits logic gatepptx
ssuser6feece1
 
There are two types of ciphers - Block and Stream. Block is used to .docx
There are two types of ciphers - Block and Stream. Block is used to .docxThere are two types of ciphers - Block and Stream. Block is used to .docx
There are two types of ciphers - Block and Stream. Block is used to .docx
relaine1
 
Bitwise
BitwiseBitwise
Bitwise
Axel Ryo
 
L2 number
L2 numberL2 number
L2 number
mondalakash2012
 
04-logic-gates (1).ppt
04-logic-gates (1).ppt04-logic-gates (1).ppt
04-logic-gates (1).ppt
DrFarahAbbasNaser
 
bits.ppt
bits.pptbits.ppt
bits.ppt
MMichaelGuelcan
 
Lecture 18 M - Copy.pptx
Lecture 18 M - Copy.pptxLecture 18 M - Copy.pptx
Lecture 18 M - Copy.pptx
AzeenShahid
 
Digital Logic Design.pptx
Digital Logic Design.pptxDigital Logic Design.pptx
Digital Logic Design.pptx
AminaZahid16
 
Lec10-CS110 Computational Engineering
Lec10-CS110 Computational EngineeringLec10-CS110 Computational Engineering
Lec10-CS110 Computational Engineering
Sri Harsha Pamu
 
Minimizing boolean
Minimizing booleanMinimizing boolean
Minimizing boolean
belcy d mathews
 
Minimizing boolean
Minimizing booleanMinimizing boolean
Minimizing boolean
belcy d mathews
 
Grafica funciones cuadráticas
Grafica funciones cuadráticasGrafica funciones cuadráticas
Grafica funciones cuadráticas
bibliotecalcr
 
Management Science
Management Science Management Science
Management Science
Renzhie Katigbak
 
Binomial Theorem
Binomial TheoremBinomial Theorem
Binomial Theorem
itutor
 
Binomial theorem
Binomial theorem Binomial theorem
Binomial theorem
Harshit Sharma
 

Similar to Lec06-CS110 Computational Engineering (20)

UNIT-1_CSA.pdf
UNIT-1_CSA.pdfUNIT-1_CSA.pdf
UNIT-1_CSA.pdf
 
3306565.ppt
3306565.ppt3306565.ppt
3306565.ppt
 
03_NumberSystems.pdf
03_NumberSystems.pdf03_NumberSystems.pdf
03_NumberSystems.pdf
 
Digital logic
Digital logicDigital logic
Digital logic
 
boolean algebra and logic simplification
boolean algebra and logic simplificationboolean algebra and logic simplification
boolean algebra and logic simplification
 
Digital-Logic40124sequential circuits logic gatepptx
Digital-Logic40124sequential circuits logic gatepptxDigital-Logic40124sequential circuits logic gatepptx
Digital-Logic40124sequential circuits logic gatepptx
 
There are two types of ciphers - Block and Stream. Block is used to .docx
There are two types of ciphers - Block and Stream. Block is used to .docxThere are two types of ciphers - Block and Stream. Block is used to .docx
There are two types of ciphers - Block and Stream. Block is used to .docx
 
Bitwise
BitwiseBitwise
Bitwise
 
L2 number
L2 numberL2 number
L2 number
 
04-logic-gates (1).ppt
04-logic-gates (1).ppt04-logic-gates (1).ppt
04-logic-gates (1).ppt
 
bits.ppt
bits.pptbits.ppt
bits.ppt
 
Lecture 18 M - Copy.pptx
Lecture 18 M - Copy.pptxLecture 18 M - Copy.pptx
Lecture 18 M - Copy.pptx
 
Digital Logic Design.pptx
Digital Logic Design.pptxDigital Logic Design.pptx
Digital Logic Design.pptx
 
Lec10-CS110 Computational Engineering
Lec10-CS110 Computational EngineeringLec10-CS110 Computational Engineering
Lec10-CS110 Computational Engineering
 
Minimizing boolean
Minimizing booleanMinimizing boolean
Minimizing boolean
 
Minimizing boolean
Minimizing booleanMinimizing boolean
Minimizing boolean
 
Grafica funciones cuadráticas
Grafica funciones cuadráticasGrafica funciones cuadráticas
Grafica funciones cuadráticas
 
Management Science
Management Science Management Science
Management Science
 
Binomial Theorem
Binomial TheoremBinomial Theorem
Binomial Theorem
 
Binomial theorem
Binomial theorem Binomial theorem
Binomial theorem
 

More from Sri Harsha Pamu

Lec23-CS110 Computational Engineering
Lec23-CS110 Computational EngineeringLec23-CS110 Computational Engineering
Lec23-CS110 Computational Engineering
Sri Harsha Pamu
 
Lec21-CS110 Computational Engineering
Lec21-CS110 Computational EngineeringLec21-CS110 Computational Engineering
Lec21-CS110 Computational Engineering
Sri Harsha Pamu
 
Lec19-CS110 Computational Engineering
Lec19-CS110 Computational EngineeringLec19-CS110 Computational Engineering
Lec19-CS110 Computational Engineering
Sri Harsha Pamu
 
Lec16-CS110 Computational Engineering
Lec16-CS110 Computational EngineeringLec16-CS110 Computational Engineering
Lec16-CS110 Computational Engineering
Sri Harsha Pamu
 
Lec15-CS110 Computational Engineering
Lec15-CS110 Computational EngineeringLec15-CS110 Computational Engineering
Lec15-CS110 Computational Engineering
Sri Harsha Pamu
 
Lec14-CS110 Computational Engineering
Lec14-CS110 Computational EngineeringLec14-CS110 Computational Engineering
Lec14-CS110 Computational Engineering
Sri Harsha Pamu
 
Lec13
Lec13Lec13
Lec12-CS110 Computational Engineering
Lec12-CS110 Computational EngineeringLec12-CS110 Computational Engineering
Lec12-CS110 Computational Engineering
Sri Harsha Pamu
 
Lec09-CS110 Computational Engineering
Lec09-CS110 Computational EngineeringLec09-CS110 Computational Engineering
Lec09-CS110 Computational Engineering
Sri Harsha Pamu
 
Lec08-CS110 Computational Engineering
Lec08-CS110 Computational EngineeringLec08-CS110 Computational Engineering
Lec08-CS110 Computational Engineering
Sri Harsha Pamu
 
Lec07-CS110 Computational Engineering
Lec07-CS110 Computational EngineeringLec07-CS110 Computational Engineering
Lec07-CS110 Computational Engineering
Sri Harsha Pamu
 
Lec04-CS110 Computational Engineering
Lec04-CS110 Computational EngineeringLec04-CS110 Computational Engineering
Lec04-CS110 Computational Engineering
Sri Harsha Pamu
 
Lec03-CS110 Computational Engineering
Lec03-CS110 Computational EngineeringLec03-CS110 Computational Engineering
Lec03-CS110 Computational Engineering
Sri Harsha Pamu
 
Lec02-CS110 Computational Engineering
Lec02-CS110 Computational EngineeringLec02-CS110 Computational Engineering
Lec02-CS110 Computational Engineering
Sri Harsha Pamu
 
Lec01-CS110 Computational Engineering
Lec01-CS110 Computational EngineeringLec01-CS110 Computational Engineering
Lec01-CS110 Computational Engineering
Sri Harsha Pamu
 
Lec1- CS110 Computational Engineering
Lec1- CS110 Computational EngineeringLec1- CS110 Computational Engineering
Lec1- CS110 Computational Engineering
Sri Harsha Pamu
 
Lec25-CS110 Computational Engineering
Lec25-CS110 Computational EngineeringLec25-CS110 Computational Engineering
Lec25-CS110 Computational Engineering
Sri Harsha Pamu
 
Android..imp google
Android..imp googleAndroid..imp google
Android..imp google
Sri Harsha Pamu
 
Android vulnerability study
Android vulnerability studyAndroid vulnerability study
Android vulnerability study
Sri Harsha Pamu
 
Android gui framework
Android gui frameworkAndroid gui framework
Android gui framework
Sri Harsha Pamu
 

More from Sri Harsha Pamu (20)

Lec23-CS110 Computational Engineering
Lec23-CS110 Computational EngineeringLec23-CS110 Computational Engineering
Lec23-CS110 Computational Engineering
 
Lec21-CS110 Computational Engineering
Lec21-CS110 Computational EngineeringLec21-CS110 Computational Engineering
Lec21-CS110 Computational Engineering
 
Lec19-CS110 Computational Engineering
Lec19-CS110 Computational EngineeringLec19-CS110 Computational Engineering
Lec19-CS110 Computational Engineering
 
Lec16-CS110 Computational Engineering
Lec16-CS110 Computational EngineeringLec16-CS110 Computational Engineering
Lec16-CS110 Computational Engineering
 
Lec15-CS110 Computational Engineering
Lec15-CS110 Computational EngineeringLec15-CS110 Computational Engineering
Lec15-CS110 Computational Engineering
 
Lec14-CS110 Computational Engineering
Lec14-CS110 Computational EngineeringLec14-CS110 Computational Engineering
Lec14-CS110 Computational Engineering
 
Lec13
Lec13Lec13
Lec13
 
Lec12-CS110 Computational Engineering
Lec12-CS110 Computational EngineeringLec12-CS110 Computational Engineering
Lec12-CS110 Computational Engineering
 
Lec09-CS110 Computational Engineering
Lec09-CS110 Computational EngineeringLec09-CS110 Computational Engineering
Lec09-CS110 Computational Engineering
 
Lec08-CS110 Computational Engineering
Lec08-CS110 Computational EngineeringLec08-CS110 Computational Engineering
Lec08-CS110 Computational Engineering
 
Lec07-CS110 Computational Engineering
Lec07-CS110 Computational EngineeringLec07-CS110 Computational Engineering
Lec07-CS110 Computational Engineering
 
Lec04-CS110 Computational Engineering
Lec04-CS110 Computational EngineeringLec04-CS110 Computational Engineering
Lec04-CS110 Computational Engineering
 
Lec03-CS110 Computational Engineering
Lec03-CS110 Computational EngineeringLec03-CS110 Computational Engineering
Lec03-CS110 Computational Engineering
 
Lec02-CS110 Computational Engineering
Lec02-CS110 Computational EngineeringLec02-CS110 Computational Engineering
Lec02-CS110 Computational Engineering
 
Lec01-CS110 Computational Engineering
Lec01-CS110 Computational EngineeringLec01-CS110 Computational Engineering
Lec01-CS110 Computational Engineering
 
Lec1- CS110 Computational Engineering
Lec1- CS110 Computational EngineeringLec1- CS110 Computational Engineering
Lec1- CS110 Computational Engineering
 
Lec25-CS110 Computational Engineering
Lec25-CS110 Computational EngineeringLec25-CS110 Computational Engineering
Lec25-CS110 Computational Engineering
 
Android..imp google
Android..imp googleAndroid..imp google
Android..imp google
 
Android vulnerability study
Android vulnerability studyAndroid vulnerability study
Android vulnerability study
 
Android gui framework
Android gui frameworkAndroid gui framework
Android gui framework
 

Recently uploaded

CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
camakaiclarkmusic
 
Life upper-Intermediate B2 Workbook for student
Life upper-Intermediate B2 Workbook for studentLife upper-Intermediate B2 Workbook for student
Life upper-Intermediate B2 Workbook for student
NgcHiNguyn25
 
The Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collectionThe Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collection
Israel Genealogy Research Association
 
DRUGS AND ITS classification slide share
DRUGS AND ITS classification slide shareDRUGS AND ITS classification slide share
DRUGS AND ITS classification slide share
taiba qazi
 
Liberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdfLiberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdf
WaniBasim
 
South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)
Academy of Science of South Africa
 
Introduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp NetworkIntroduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp Network
TechSoup
 
writing about opinions about Australia the movie
writing about opinions about Australia the moviewriting about opinions about Australia the movie
writing about opinions about Australia the movie
Nicholas Montgomery
 
Advanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docxAdvanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docx
adhitya5119
 
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama UniversityNatural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
Akanksha trivedi rama nursing college kanpur.
 
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
Nguyen Thanh Tu Collection
 
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
PECB
 
Hindi varnamala | hindi alphabet PPT.pdf
Hindi varnamala | hindi alphabet PPT.pdfHindi varnamala | hindi alphabet PPT.pdf
Hindi varnamala | hindi alphabet PPT.pdf
Dr. Mulla Adam Ali
 
The simplified electron and muon model, Oscillating Spacetime: The Foundation...
The simplified electron and muon model, Oscillating Spacetime: The Foundation...The simplified electron and muon model, Oscillating Spacetime: The Foundation...
The simplified electron and muon model, Oscillating Spacetime: The Foundation...
RitikBhardwaj56
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
heathfieldcps1
 
Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
Jean Carlos Nunes Paixão
 
How to Add Chatter in the odoo 17 ERP Module
How to Add Chatter in the odoo 17 ERP ModuleHow to Add Chatter in the odoo 17 ERP Module
How to Add Chatter in the odoo 17 ERP Module
Celine George
 
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptxC1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
mulvey2
 
How to Build a Module in Odoo 17 Using the Scaffold Method
How to Build a Module in Odoo 17 Using the Scaffold MethodHow to Build a Module in Odoo 17 Using the Scaffold Method
How to Build a Module in Odoo 17 Using the Scaffold Method
Celine George
 
The History of Stoke Newington Street Names
The History of Stoke Newington Street NamesThe History of Stoke Newington Street Names
The History of Stoke Newington Street Names
History of Stoke Newington
 

Recently uploaded (20)

CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
 
Life upper-Intermediate B2 Workbook for student
Life upper-Intermediate B2 Workbook for studentLife upper-Intermediate B2 Workbook for student
Life upper-Intermediate B2 Workbook for student
 
The Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collectionThe Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collection
 
DRUGS AND ITS classification slide share
DRUGS AND ITS classification slide shareDRUGS AND ITS classification slide share
DRUGS AND ITS classification slide share
 
Liberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdfLiberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdf
 
South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)
 
Introduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp NetworkIntroduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp Network
 
writing about opinions about Australia the movie
writing about opinions about Australia the moviewriting about opinions about Australia the movie
writing about opinions about Australia the movie
 
Advanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docxAdvanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docx
 
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama UniversityNatural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
 
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
 
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
 
Hindi varnamala | hindi alphabet PPT.pdf
Hindi varnamala | hindi alphabet PPT.pdfHindi varnamala | hindi alphabet PPT.pdf
Hindi varnamala | hindi alphabet PPT.pdf
 
The simplified electron and muon model, Oscillating Spacetime: The Foundation...
The simplified electron and muon model, Oscillating Spacetime: The Foundation...The simplified electron and muon model, Oscillating Spacetime: The Foundation...
The simplified electron and muon model, Oscillating Spacetime: The Foundation...
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
 
Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
 
How to Add Chatter in the odoo 17 ERP Module
How to Add Chatter in the odoo 17 ERP ModuleHow to Add Chatter in the odoo 17 ERP Module
How to Add Chatter in the odoo 17 ERP Module
 
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptxC1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
 
How to Build a Module in Odoo 17 Using the Scaffold Method
How to Build a Module in Odoo 17 Using the Scaffold MethodHow to Build a Module in Odoo 17 Using the Scaffold Method
How to Build a Module in Odoo 17 Using the Scaffold Method
 
The History of Stoke Newington Street Names
The History of Stoke Newington Street NamesThe History of Stoke Newington Street Names
The History of Stoke Newington Street Names
 

Lec06-CS110 Computational Engineering

  • 1. CS110: Models of Computing Lecture 6 V. Kamakoti 14th January 2008
  • 2. Today’s Lecture Contents • Solving Quadratic Equations • Given ax2 + bx + c = 0 • The roots are • (-b + SQRT(b2 - 4ac))/2a • (-b - SQRT(b2 - 4ac))/2a • New things • • • • Check if ‘a’ is 0 Check if ‘b’ is 0 Check if discriminant is < 0 Calculate SQRT
  • 3. Calculate SQRT • Input a double precision float and get a double precision float as output • The function “sqrt” is in <math.h> like how “printf” is in <stdio.h> • There is another function “sqrtl” also - find out what it does? • Use “Manual pages” in Unix – Type the command “man sqrt” and you shall get the details.
  • 4. The Program #include <stdio.h> #include <math.h> main() { double a,b,c,DISC,R1,R2; printf(“Enter a ?n”); scanf(“%f”,&a); //Similarly for b and c
  • 5. The Program if (a == 0) { printf(“The equation is not Quadratic n”); if (b == 0) printf(“No equation at alln”); else printf(“Root is %fn”, -c/b); } else
  • 6. Program { DISC = b*b - 4*a*c; //Operator Precedence if (DISC < 0) { printf(“No real solution existsn”); } else { //Paranthesis to handle precedence R1 = (-b + sqrt(DISC))/(2*a)); R2 = (-b - sqrt(DISC))/(2*a)); //Print the roots } } }
  • 7. Polynomial Multiplication • Input: Coefficients of two polynomials P1 and P2 of degree 5 • Output: Coefficients of the polynomial, which is the product of P1 and P2. • Do not forget: There are Twelve Inputs and Eleven Outputs
  • 8. Polynomial multiplication • (a1x + a0 ) (b1x + b0 ) – a1b1x2 + (a0b1 +a1b0 ) x + a0b0 • The coefficient of xk is sum of aibj’s such that i +j=k • In the program you have A0, A1,… A5 and B0, B1,…, B5 for the coefficients of the input polynomials and C0, C1, …., C10 for the coefficients of the output polynomial.
  • 9. For your problem • • • • • • C0 = A0 * B0; C1 = A0*B1 + B1*A0 ……. C8 = A3*B5 + A4*B4 + A5*B3 C9 = A4*B5 + B4*A5 C10 = A5 * B5
  • 10. The problem • Suppose there are n = 2k persons, each with a certain item of information. In each step, each person can communicate with another person and share all the information he or she knows (including information learned in previous steps). A person cannot communicate with more than one person in any step. Design a communication (gossip) pattern such that after log2n (= k) steps, everyone knows everything.
  • 11. Solution • Numbering problem – Number “N” people using integers 0 to N-1. – N = 2k – Group pairs of two - Number each 0,1 – Group pairs of these and prefix 0 to numbers in one pair and prefix 1 to numbers in the other pair. – Repeat till only one group exist
  • 13. Solution - Step 1 0 1 0 1 0 Groups of two 1 0 1
  • 14. Solution - Step 2 00 01 10 11 00 Groups of four 01 10 11
  • 15. Solution - Step 3 000 001 010 011 100 Groups of eight 101 110 111
  • 16. Gossip - Step 1 0 1 0 1 0 Groups of two 1 0 1
  • 17. Gossip - Step 2 00 01 10 11 00 Groups of four 01 10 11
  • 18. Gossip - Step 3 000 001 010 011 100 101 110 Groups of eight - k-bits for n = 2k 111
  • 19. Solution at a glance - Step 1 000 001 010 011 100 101 110 111
  • 20. Solution at a glance - Step 2 000 001 010 011 100 101 110 111
  • 21. Solution at a glance - Step 3 000 001 010 011 100 101 110 111
  • 22. Creative Question - 3 • You are given a BLACK BOX - nothing is known what is inside it - but it does the following for you – Give a sequence of n real numbers and an integer k, the box will output “yes” or “no” indicating whether there is a subset of the numbers whose sum is exactly “k”. It will not tell you the subset. – Use this black box to find the subset whose sum is “k”, if it exists. – You are allowed to use the black box exactly “n” times, where “n” is the length of the sequence.
  • 23. Example (1.3,.7,2.5,1.7) and k=3 Yes The problem is using the above box exactly four times you Should find out the subset that adds to 3, namely (1.3,1.7)
  • 24. Example (1.3,.7,2.5,1.7) and k=3 Yes All elements distinct Remove an element and ask if it solves Yes: element not in subset No: element is in the subset