lec2 - % Quad1 % Solves x^2 + 5x + 6 = 0 a = 1; b = 5; c =...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
% Quad1 % Solves x^2 + 5x + 6 = 0 a = 1; b = 5; c = 6; d = sqrt(b^2 -4*a*c); r1 = (-b-d)/(2*a) r2 = (-b+d)/(2*a) % Quad2 % Solves ax^2 + bx + c = 0 a = input('Enter a: '); b = input('Enter b: '); c = input('Enter c: '); d = sqrt(b^2 -4*a*c); r1 = (-b-d)/(2*a) r2 = (-b+d)/(2*a) % Quad3 % Solves ax^2 + bx + c = 0 % Assumes real roots. % Formatted output clc a = input('Enter a: '); b = input('Enter b: '); c = input('Enter c: '); d = sqrt(b^2 -4*a*c); r1 = (-b-d)/(2*a); r2 = (-b+d)/(2*a); disp(' ') disp(sprintf('Root1 = %10.6f',r1)) disp(sprintf('Root2 = %10.6f',r2)) % OutputStyles % Clear the screen clc % A message and a blank line. .. disp('Leave the semicolon off to see the result of an assignment.')
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
disp(' ') x = sqrt(2) % When printing this way, two output styles are available. % For 5 significant digits. .. format short x = 9.12345678901234 y = pi % For 15 significant digits. .. format long x = 9.12345678901234 y = pi % Formatted output. disp(' ') x = 543210.123456789; disp(sprintf('x = %15.1f',x)) disp(sprintf('x = %15.2f',x)) disp(sprintf('x = %15.3f',x)) disp(sprintf('x = %15.4f',x)) disp(sprintf('x = %15.5f',x)) disp(' ') disp(sprintf('x = %15.1e',x)) disp(sprintf('x = %15.2e',x)) disp(sprintf('x = %15.3e',x))
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 08/27/2008 for the course CS 100 taught by Professor Fan/vanloan during the Fall '07 term at Cornell University (Engineering School).

Page1 / 7

lec2 - % Quad1 % Solves x^2 + 5x + 6 = 0 a = 1; b = 5; c =...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online