SlideServe
Menu
Préférences
© SlideServe · v2026

Algorithm Development in Mathematics & Computer Science

fredgarcia avatar
14 diapositives · 214 Views · Jan 06, 2020

Learn to develop algorithms using systematic procedures & pseudo-code to solve problems efficiently. Understand quadratic equation solutions through structure plans & MATLAB coding examples.

Algorithm Development in Mathematics & Computer Science - slide 1
01 / 14Algorithm Development in Mathematics & Computer Science
1 / 17

Télécharger la présentation

Algorithm Development in Mathematics & Computer Science
Une image / un lien ci-dessous est fourni (tel quel) pour télécharger la présentation

Politique de téléchargement : le contenu du site vous est fourni TEL QUEL pour votre information et votre usage personnel ; il ne peut être vendu, concédé sous licence ni partagé sur d’autres sites sans l’accord de son auteur.Le contenu vous est fourni TEL QUEL, pour votre information et votre usage personnel uniquement. Téléchargez la présentation en cliquant sur ce lien. Lors du téléchargement, si vous ne parvenez pas à télécharger une présentation, l’éditeur a peut-être supprimé le fichier de son serveur.Pendant le téléchargement, si vous ne parvenez pas à obtenir une présentation, le fichier a peut-être été supprimé par l’éditeur.

F I N

Plus de contenu associé

Transcription de la présentation
  1. Computer Simulation “Lecture 4” Electrical and Computer Engineering Department SUNY – New Paltz SUNY-New Paltz

  2. Developing algorithms · structure plan (pseudo- code) ·systematic procedureor algorithm SUNY-New Paltz

  3. What is an Algorithm? In mathematics and computer science, an algorithm is an unambiguous specification of how to solve a class of problems. Starting from an initial state and initial input, the instructions describe a computation that, when executed, proceeds through a finite number of well-defined successive states, eventually producing "output" SUNY-New Paltz

  4. Structure plans Solving Quadratic Equation ax2+ bx + c = 0 • Input data • Second Order(a=0)? • If not x=-c/b • Is (b2-4ca)<0 • If yes then complex roots • Otherwise x1,2= (± b + √b2 − 4ac)/(2a) SUNY-New Paltz

  5. Pseudo Code • Input data Start Input data (a, b, c) If a = 0 then If b = 0 then If c = 0 then Display ‘Solution indeterminate’ else Display ‘There is no solution’ else x = −c/b Display x (only one root: equation is linear) else if b2 < 4ac then Display ‘Complex roots’ else if b2 = 4ac then x = −b/(2a) Display x (equal roots) else x1 = (−b + √b2 − 4ac)/(2a) x2 = (−b − √b2 − 4ac)/(2a) Display x1, x2 Stop. • Second Order(a=0)? • If not x=-c/b • Is (b2-4ca)<0 • If yes then complex roots • Otherwise x1,2= (± b + √b2 − 4ac)/(2a) SUNY-New Paltz

  6. MATLAB CODE(2) Start Input data (a, b, c) If a = 0 then If b = 0 then If c = 0 then Display ‘Solution indeterminate’ else Display ‘There is no solution’ else x = −c/b Display x (only one root: equation is linear) else if b2 < 4ac then Display ‘Complex roots’ else if b2 = 4ac then x = −b/(2a) Display x (equal roots) else x1 = (−b + √b2 − 4ac)/(2a) x2 = (−b − √b2 − 4ac)/(2a) Display x1, x2 Stop. a = input('Enter a :'); b = input('Enter b :'); c = input('Enter c :'); if a == 0 if b == 0 if c == 0 display( 'Solution indeterminate!'); else display('There is no solution'); end else x==-c/b; display(['only one root: equation is linear, x=', num2str(x)]); end else if b*b < 4*a*c display('Complex roots') else if b*b == 4*a*c x = -b/(2*a) display(['equal roots, x1=x2=',num2str(x)]); else x1 = (-b + sqrt(b*b - 4*a*c))/(2*a); x2 = (-b - sqrt(b*b - 4*a*c))/(2*a); display (['distinct roots x1=', num2str(x1),' x2=', num2str(x2)]); end end end SUNY-New Paltz

  7. START b2 – 4ac>0? N a = 0 ? Y x1,2 =(±b+sqrt(b2 – 4ac))/2a b = 0 ? N x=-c/b c = 0 ? Y N Flow Chart Input coefficients Y Y SOLUTION INDETERMINATE! COMPLEX SOLUTIONS! THERE IS NO SOLUTION! SUNY-New Paltz

  8. START INPUT COEFFICIENTS b2 – 4ac>0 ? a = 0 ? N Y x1,2 =(±b+sqrt(b2 – 4ac))/2a b = 0 ? N x=-c/b c = 0 ? SOLUTION INDETERMINATE! Y COMPLEX SOLUTIONS! N THERE IS NO SOLUTION! MATLAB CODE(3) a = input('Enter a :'); b = input('Enter b :'); c = input('Enter c :'); if a == 0 if b == 0 if c == 0 display( 'Solution indeterminate!'); else display('There is no solution'); end else x==-c/b; display(['only one root: equation is linear, x=', num2str(x)]); end else if b*b < 4*a*c display('Complex roots') else if b*b == 4*a*c x = -b/(2*a) display(['equal roots, x1=x2=',num2str(x)]); else x1 = (-b + sqrt(b*b - 4*a*c))/(2*a); x2 = (-b - sqrt(b*b - 4*a*c))/(2*a); display (['distinct roots x1=', num2str(x1),' x2=', num2str(x2)]); end end end N Y Y SUNY-New Paltz

  9. Components of Flowchart SUNY-New Paltz

  10. Example of a Flowchart SUNY-New Paltz

  11. Example of a Flowchart SUNY-New Paltz

  12. Exercise • Write a flow chart that implements the following algorithm: • A single die is rolled • If it is even, print “Even Roll!” • If it is odd, print “Odd Roll” • Modify the process to roll indefinitely! SUNY-New Paltz

  13. Exercise SUNY-New Paltz

  14. Exercise • Write a flow chart that implements the following algorithm: • Set vector V=[ 2, 5, -1, 6, 0] • Initialize variable maximum myMax = 2 • Search through the vector and compare all the elements of the vector to find the maximum of the vector. SUNY-New Paltz