Mathematics

profileUnknownp



Question 1


Answer the questions below...

Login to MATLAB

Try the following: cut and paste in MATLAB a few lines a ta at time:

% chars hold single characters

c1 = 'A'

%-------------------------------------------------------------

% class displays the data type

class(c1)

%-------------------------------------------------------------

% You can store strings in single quotes

s1 = 'A string'

class(s1)

%-------------------------------------------------------------

% Booleans map true to 1 and false to 0 

7 > 3

b1 = true

%-------------------------------------------------------------

% Show max & min values

intmin('int8')

intmax('int8')

% Largest double

realmax

% Largest int

realmax('single')

%-------------------------------------------------------------

% You can continue expressions using ...

% Suppress output with a ;

v1 = 1 + 2 + 3 + 4...

+ 5;

% Everything defaults to double precision

v2 = 7

class(v2)

%-------------------------------------------------------------

% Cast to int8

% The term casting refers to the change of the type

% without transformation of its content

v3 = int8(v2)

class(v3)

% Convert char to double

v4 = double('A')

% Convert to char

v5 = char(64)

%-------------------------------------------------------------

% sprintf formats a string

% %d : Integers, %f : Floats, %e : exponential notation

% %c : Characters, %s : Strings

fprintf('5 + 4 = %d\n', 5 + 4)

fprintf('5 - 4 = %d\n', 5 - 4)

fprintf('5 * 4 = %d\n', 5 * 4)

% Define you want only 2 decimals

fprintf('5 / 4 = %0.2f\n', 5 / 4)

% Exponentiation

fprintf('5^4 = %d\n', 5^4)

% Modulus (Escape % by doubling)

fprintf('5 %% 4 = %d\n', mod(5,4))

% Generate a random value between 10 & 20

randi([10,20])

% Precision is accurate to 15 digits by default

bF = 1.1111111111111111

bF2 = bF + 0.1111111111111111

fprintf("bF2 = %0.16f\n", bF2)

%-------------------------------------------------------------

% help elfun shows a list

fprintf('abs(-1) = %d\n', abs(-1))

fprintf('floor(2.45) = %d\n', floor(2.45))

fprintf('ceil(2.45) = %d\n', ceil(2.45))

fprintf('round(2.45) = %d\n', round(2.45))

fprintf('exp(1) = %f\n', exp(1)) % e^x

fprintf('log(100) = %f\n', log(100))

fprintf('log10(100) = %f\n', log10(100))

fprintf('log2(100) = %f\n', log2(100))

fprintf('sqrt(100) = %f\n', sqrt(100))

fprintf('90 Deg to Radians = %f\n', deg2rad(90))

%-------------------------------------------------------------

% Relational Operators : >, <, >=, <=, == and ~=

% Logical Operators : ||, &&, ~ (Not)

Try writing a few conditional statements.


Question 2

For MATLAB - Find an algorithm to perform the Bisection method and execute the following.

  1. Square root of 7. Guess a is 2, guess b is 3. 10 iterations.
  2. Square root of 11. guess A is 3, guess B is 4. 10 iterations.
  3. Square root of 11. guess A is 2, guess B is 5. 10 iterations.
  4. From question a and b - which is more accurate?
  5. Repeat c with 30 iterations. Write your observation(s) of the result.

** This is a MATLAB assignment


    • 3 years ago
    • 15
    Answer(1)

    Purchase the answer to view it

    blurred-text
    NOT RATED
    • attachment
      Q1.m
    • attachment
      Matlab.docx
    • attachment
      Question1.docx