{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

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

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 Document Right 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)) disp(sprintf('x = %15.4e',x)) disp(sprintf('x = %15.5e',x)) % Script spiral % Draws a logarithmic spiral % Parameters of the spiral: turnAngle= 100;
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.

{[ snackBarMessage ]}