Create a Matlab function called change1tup. n whose purpose is to add up the val
ID: 3791648 • Letter: C
Question
Create a Matlab function called change1tup. n whose purpose is to add up the value of all the coins in your pocket. Specifically, given a vector coins (which contains as its elements the number of pennies, nickels, dimes, and quarters in your pocket, in that order), determine the total value in dollars of those coins all together and return the result as a single value called dollars. Function specifications and some sample function calls are shown below. input parameter coins a vector (list) of the number of coins from your pocket (in the order of pennies, nickels, dimes, and quarters) output parameter dollars the total in dollars that your coins are worth sample function calls change 1 up ([2.3.4.5]) produces the value 1. 82 change1tup([7, 1, 0, 3]) produces the value 0.87 Assuming a single one-time deposit, the amount of money in a savings account after t years is A = P(1 + r/n)^nl where P is the principal deposited, r is the annual interest rate (expressed as a decimal), and n is the number of interest payments per year (n = 2, semiannual: n = 4, quarterly; n = 12, monthly; etc.) Write a Matlab function called save me. n to calculate the value of your savings. The function specifications are listed below. You function should work is you provide either single numbers or sectors for both the principal P and the interest rate r (see examples below for how vector inputs are supposed to with this function). input parameters P the principal deposited r the annual interest rate n the number of interest payments/year t the number of years output parameter A the amount(s) in the account sample function calls save (50, 0.08, 12, 20) produces 246.3401 save ne([25, 50, 75], 0.04, 4, 10) produces [37.2216, 74.4432, 111.6648] save ne(50, [0.04, 0.06], 12, 20) produces [111. 1291, 165.5102] save ne ([40, 60], [0.05, 0.07], 2, 25) produces [137.4843, 335.0956]Explanation / Answer
[1]
function dollars = change1tup(coins)
sum = 0;
sum = sum + coins(1)*1;
sum = sum + coins(2)*5;
sum = sum + coins(3)*10;
sum = sum + coins(4)*25;
dollars = sum/100;
X = sprintf('produce the value %0.2f',dollars);
disp(X)
end
[2]
function [A] = saveme(p,r,n,t)
k = 0;
for i = 1:length(p)
for j = 1:length(r)
a = (r(j)/n);
b = n*t;
c = (1 + a).^b;
amount = p(i)*c;
k = k + 1;
A(k) = amount;
end
end
end