Question

Problem 1.3 In this example we will compare how the return to saving depends on how frequently interest is compounded. We say

in julia
0 0
Add a comment Improve this question Transcribed image text
Answer #1

ANSWER;

function R(r, n)
return (1+r/n)^n
end

r = 0.10

# using loop
loopAns = Float64[] # empty vector
for i = 1:100 # for-loop
push!(loopAns, R(r,i)) # push return value
end
println("Calcuated return using for-loop\n",loopAns)

# using vectorization
n = collect(1:100) # vector containing values from 1 to 100
vectorAns = R.(r,n)
println("Calcuated return using vectorization\n",vectorAns)

Output:

1.li Result $julia main.jl Calcuated return using for-loop (1.1, 1.1025, 1.10337, 1.10381, 1.10408, 1.10426, 1.10439, 1.10449

Add a comment
Know the answer?
Add Answer to:
in julia Problem 1.3 In this example we will compare how the return to saving depends...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
Active Questions
ADVERTISEMENT