0% found this document useful (0 votes)
134 views

Laporan Syntax Pemrograman MATLAB

This document contains 4 tasks related to solving quadratic equations in MATLAB. Task 1 evaluates 2 expressions. Task 2 creates a script that takes coefficients a, b, c as input and outputs the roots of the equation ax^2 + bx + c = 0. Task 3 runs the script with different coefficient values. Task 4 creates a function that takes coefficients as input and returns the roots of the quadratic equation. The function is tested on some examples.

Uploaded by

Anjar Ajja
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
134 views

Laporan Syntax Pemrograman MATLAB

This document contains 4 tasks related to solving quadratic equations in MATLAB. Task 1 evaluates 2 expressions. Task 2 creates a script that takes coefficients a, b, c as input and outputs the roots of the equation ax^2 + bx + c = 0. Task 3 runs the script with different coefficient values. Task 4 creates a function that takes coefficients as input and returns the roots of the quadratic equation. The function is tested on some examples.

Uploaded by

Anjar Ajja
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

Nama : Ginanjar Adhi Pamungkas

Puri Suci Sugesti


Budi Prasetyo
PTE 10 off A

PERCOBAAN 1
MENGENAL SINTAK SINTAK PEMROGRAMAN DI MATLAB

TUGAS 1

x = 4+2^3-sqrt(4^2-7)/(2^2-1)*4^2-1
y = 1+(3^2-4)^2/(sqrt(2^4+9)+5)*2^3

HASIL
>> prak1

x=

-5

y=

21

TUGAS 2

% Script file: rootsquad


% Return the roots of the equation of the form ax^2+bx+c=0
disp('***************************************************') % display
messages
disp(' This script file solves for the roots of the ');
disp('quadratic equation of the form: ax^2+bx+c=0');
disp('***************************************************')
a = input('*** Enter the coefficient a :');
b = input('*** Enter the coefficient b :'); % the inputs a assignedto a, b
and c
c = input('*** Enter the coefficient c :');
disp('***************************************************')
disp('The roots of the quadratic equation')
disp('of the form: ax^2+bx+c=0, are :')
root1 = (-b+sqrt(b^2-4*a*c))/(2*a) % display the roots
root2 = (-b-sqrt(b^2-4*a*c))/(2*a)
disp('***************************************************')

HASIL
>> prak2
***************************************************
This script file solves for the roots of the
quadratic equation of the form: ax^2+bx+c=0
***************************************************
*** Enter the coefficient a :2
*** Enter the coefficient b :2
*** Enter the coefficient d :2
***************************************************
The roots of the quadratic equation
of the form: ax^2+bx+c=0, are :
root1 =
-0.5000 + 0.8660i
root2 =
-0.5000 - 0.8660i

TUGAS 3

HASIL
>> prak2
***************************************************
This script file solves for the roots of the
quadratic equation of the form: ax^2+bx+c=0
***************************************************
*** Enter the coefficient a :2
*** Enter the coefficient b :3
*** Enter the coefficient d :7
***************************************************
The roots of the quadratic equation
of the form: ax^2+bx+c=0, are :
root1 =
-0.7500 + 1.7139i
root2 =
-0.7500 - 1.7139i

>> prak2
***************************************************
This script file solves for the roots of the
quadratic equation of the form: ax^2+bx+c=0
***************************************************
*** Enter the coefficient a :pi
*** Enter the coefficient b :2*pi

*** Enter the coefficient d :3*pi


***************************************************
The roots of the quadratic equation
of the form: ax^2+bx+c=0, are :
root1 =
-1.0000 + 1.4142i
root2 =
-1.0000 - 1.4142i
***************************************************

>> prak2
***************************************************
This script file solves for the roots of the
quadratic equation of the form: ax^2+bx+c=0
***************************************************
*** Enter the coefficient a :log10(32.3)
*** Enter the coefficient b :sqrt(3^3+1.33^3.3)
*** Enter the coefficient d :tan(1.112)
***************************************************
The roots of the quadratic equation
of the form: ax^2+bx+c=0, are :
root1 =
-0.4217
root2 =
-3.1810
***************************************************

TUGAS 4

function [root1,root2] = func_quad_sol(a,b,c)


% function file : func_quad_sol
% Returns the roots of the equation: ax^2 + bx + c = 0
% The outputs are: roots1 and root 2
% The inputs are the coefficients: a, b, and c
disp('***********************************************');
disp(' This function file solves for the roots of the '); % display message
disp('quadratic equation of the form: ax^2+bx+c=0'); % display message
disp('given the coefficients a, b, and c as inputs'); % display message
root1 = (-b+sqrt(b^2-4*a*c))/(2*a); % the roots are evaluated
root2 = (-b-sqrt(b^2-4*a*c))/(2*a);
disp('*************The roots are:*******************'); % display message
root1 % returns roots
root2
disp('***********************************************'); %display message

HASIL
>> func_quad_sol(2,3,7)
***********************************************
This function file solves for the roots of the
quadratic equation of the form: ax^2+bx+c=0
given the coefficients a, b, and c as inputs
*************The roots are:*******************
root1 =
-0.7500 + 1.7139i
root2 =
-0.7500 - 1.7139i
***********************************************
ans =
-0.7500 + 1.7139i

>> func_quad_sol(pi,2*pi,3*pi)
***********************************************
This function file solves for the roots of the
quadratic equation of the form: ax^2+bx+c=0
given the coefficients a, b, and c as inputs
*************The roots are:*******************
root1 =
-1.0000 + 1.4142i
root2 =
-1.0000 - 1.4142i
***********************************************
ans =
-1.0000 + 1.4142i

>> func_quad_sol(log10(32.3), sqrt(3^3+1.33^3.3),tan(1.112))


***********************************************
This function file solves for the roots of the
quadratic equation of the form: ax^2+bx+c=0
given the coefficients a, b, and c as inputs
*************The roots are:*******************
root1 =
-0.4217
root2 =
-3.1810
***********************************************
ans =
-0.4217

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