Start learning today, and be successful in your academic & professional career. Start Today!

• ## Related Books

 0 answersPost by Neil Tugby on August 31, 2014In the practice question, the input X = 0 < 0.5 < 1 returns 0, even though all statements are true.  If X = 0 < 1<10 is entered however, the result is 1.  Can u please explain why this happens? 0 answersPost by Tony Matth on June 5, 2014You first wrote disp([ti tax])(@7.48) and then wrote disp([inc' tax']) (@10.45). You didn't use the symbol ' for the first operator, however display results are same. Why is that?

### Logical Vectors, Part 2

• We can use rational operators to construct logical values and vectors, moreover we have the following logical operands as well:
• Operator ~ Meaning NOT
• Operator & Meaning AND
• Operator | Meaning OR
• A more comprehensive operator precedence table is as follows, note that you can use rational operators as logical operators as well:
• Precedence 1   Operators ()
• Precedence 2   Operators ^ .^ ‘ .’ (pure transpose)
• Precedence 3   Operators + (unary plus) – (unary minus) ~ (NOT)
• Precedence 4   Operators / \ .* ./ .\
• Precedence 5   Operators + (addition) – (subtraction)
• Precedence 6   Operators :
• Precedence 7   Operators < >= <= == ~=
• Precedence 8   Operators & (AND)
• Precedence 9   Operators | (OR)

### Logical Vectors, Part 2

Without using MATLAB, guess what is the value of x in each case:
X = 3 > 2
X = 2 > 3
X = 0 < 0.5 < 1
X = 3 > 2
X = 1

X = 2 > 3
X = 0

X = 0 < 0.5 < 1
X = 0
A mortgage bond (loan) of amount L is obtained to buy a house. The interest rate r is 15 percent (0.15) p.a. The fixed monthly payment P which will pay off the bond exactly over N years is given by the formula:

P = [(rL(1+r/12)12N)/(12[(1+r/12)12N−1])]

(a) Write a program to compute and print P if N = 20 years, and the bond is for \$50 000. You should get \$658.39

(b) It's interesting to see how the payment P changes with the period N over which you pay the loan. Run the program for different values of N (use input)
See if you can find a value of N for which the payment is less than \$625

(c) Now go back to having N fixed at 20 years, and examine the effect of different interest rates. You should see that raising the interest rate by 1 percent (0.01) increases the monthly payment by about \$37
r = 0.15;
N = 20;
L = 50000;
P = (r*L*((1+r/12) (12*N)))/(12*((1+r/12) (12*N)-1))

N = input('please enter number of years: ');
P = (r*L*((1+r/12) (12*N)))/(12*((1+r/12) (12*N)-1))
It's useful to be able to work out how the period of a bond repayment changes if you increase or decrease your monthly payment P. The formula for the number of years N to repay the loan is given by

N=[(ln([P/(P−rL/12)]))/(12ln(1+r/12))]

(a) Write a new program to compute this formula. Use the built-in function log for the natural logarithm ln. How long will it take to pay off the loan of \$50000 at \$800 a month if the interest remains at 15 percent?

(b) Use your program to find out by trial-and-error the smallest monthly payment that can be made to pay the loan off this side of eternity. Hint: Recall that it is not possible to find the logarithm of a negative number, so P must not be less than rL/12.
(a)10.2 years — nearly twice as fast as when paying \$658 a month!

(b) r = 0.15;
N = 20;
L = 50000;
P = (r*L*((1+r/12) (12*N)))/(12*((1+r/12) (12*N)-1))

r = r+ 0.01;
P2 = (r*L*((1+r/12) (12*N)))/(12*((1+r/12) (12*N)-1))

change = P2 - P

r = 0.15;
L = 50000;
P = 800;
N = log(P/(P−r*L/12))/(12*log(1+r/12))

P = r*L/12 + eps;
N = log(P/(P−r*L/12))/(12*log(1+r/12));
while N  >  30
P = P + 0.01;
N = log(P/(P−r*L/12))/(12*log(1+r/12));
end

*These practice questions are only helpful when you work on them offline on a piece of paper and then use the solution steps function to check your answer.

### Logical Vectors, Part 2

Lecture Slides are screen-captured images of important points in the lecture. Students can download and print out these lecture slide images to do practice problems as well as take notes while watching the lecture.

• Intro 0:00
• Logical Operators and Vectors 0:09
• Logical Functions 1:09
• Any
• Exist
• Find(x) 2:20
• Defining a New Vector