Can you please solve using MATLAB You have a friend who goes

Can you please solve using MATLAB

You have a friend who goes on a vacation with $ X in his account. On the first day he spends $ Y. On each subsequent day, if the day is warm he spends p% more than the previous day and if the day is cold, he spends q% less than the previous day. It turns out that the first day is warm, but every k-th day is cold. Write a script file called vacation which will allow you to input X, Y, p, q, and k and compute how long your friend\'s vacation will last (the vacation ends when he runs out of money) Test your program with X = $ 500, Y = $ 30, p = 20%, q = 30%, and k = 4

Solution

function V = vacation(X,Y,p,q,k)
V = X;
V = V - Y;%first day
lastspend = Y;
count =1;
while V>0
if rem(count,k)==0%this condition satisfies every kth day which will be cold
perc = lastspend*(1-(0.01*q));
V = V-perc;
lastspend = perc;
else%this condition satisfies other days which I have assumed as old
perc = lastspend*(1+(0.01*p));
V = V-perc;
lastspend = perc;
end
count = count+1;
end
disp(\'days\');
disp(count);
end

Can you please solve using MATLAB You have a friend who goes on a vacation with $ X in his account. On the first day he spends $ Y. On each subsequent day, if t

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site