0% found this document useful (0 votes)
7 views2 pages

Kadri Mohamed Hamza

Uploaded by

youcefkhelifa506
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views2 pages

Kadri Mohamed Hamza

Uploaded by

youcefkhelifa506
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

KADRI Mohamed Hamza

Tp anal num homework


1)
% Linear equation f1(x) = ax + b = 0
disp('Solving the linear equation f1(x) = ax + b = 0');
% Input the coefficients
input ('a');
input ('b');
% Check if a is zero
if 'a' == 0
disp('Error: Coefficient a cannot be zero for a linear equation.');
else
% Solve the equation
x=-b/a;
disp(x)
end
2)
disp('Solving the quadratic equation f2(x) = ax^2 + bx + c = 0');
% Input the coefficients
a = input('Enter the coefficient a: ');
b = input('Enter the coefficient b: ');
c = input('Enter the coefficient c: ');

% Check if a is zero
if a == 0
disp('Error: Coefficient a cannot be zero for a quadratic equation.');
else
% Compute the discriminant
discriminant = b^2 - 4*a*c;
disp('The discriminant is: ')
disp(discriminant);
% Determine the nature of the roots based on the discriminant
if discriminant > 0
% Two real roots
root1 = (-b + sqrt(discriminant)) / (2*a); root2 = (-b - sqrt(discriminant)) / (2*a);
disp(['root1 = ', num2str(root1), ', root2 = ', num2str(root2)]);
elseif discriminant == 0
% One real root
root = -b / (2*a);disp(['One real root: x = ', num2str(root)]);
else
% No real roots (negative discriminant)
disp('No real solution exists (discriminant < 0)');
end
end

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy