BME1901 Week 2
BME1901 Week 2
• Grading:
• Midterm exam 30%
• Project 30%
• Final exam 40%
primes(7) =
primes() Generate list of prime numbers [2,3,5,7]
Array elements that are prime
isprime() isprime([6,7]) = [0,1]
numbers
sign() sign(3+4i)=0.6+0.8i
-
• Each trig function can be used for the inputs in degrees by adding “d” at the
end of the function.
Example: sind(90)=1.
X = sqrtm(A) →
sqrtm() Matrix square root X*X = A
D=
16.7075 0 0
0 -0.9057 0
0 0 0.1982
>> A = [3,5,1;1,1,0;0,3,5];
>> B = [16;3;21];
>> linsolve(A,B)
ans =
1.0000
2.0000
3.0000
Introductory Computer Sciences 2023-2024
17
Fall Week #2
Linear systems
4𝑥 + 5𝑦 = 6
3𝑥 − 2𝑦 = 14
a = 1; % value of a
b = 2; % value of b
c = 3; % value of c
sum = a b + c; % result
??? sum = a b + c; % result
|
Error: Unexpected MATLAB expression.
• The string, which is the first argument inside the fprintf function,
contains a placeholder (%) where the value of the variable (in this
case, x) will be inserted. The placeholder also contains formatting
information (see next slide).
• “\n” causes MATLAB to start a new line, we need to use \n, called a
linefeed, at the end of the string.
Format Description
%d Base 10 values
%e Exponential notation (3.141593e+00)
%f Fixed-point notation
%g The more compact of %e or %f, with no trailing zeros
%E Same as %e, but uppercase (3.141593E+00)
%G The more compact of %E or %f, with no trailing zeros
%c Single character
%s String of characters
%o Base 8 (octal)
%u Base 10
%x Base 16 (hexadecimal), lowercase letters
%X Same as %x, uppercase letters