Question

In: Computer Science

PLEASE ANSWER IN MATLAB Problem 2 Continuation of HW2, Problem 2: Total Solar Eclipse (TSE) budgeting....

PLEASE ANSWER IN MATLAB

Problem 2

Continuation of HW2, Problem 2: Total Solar Eclipse (TSE) budgeting.

This problem will help your program be more usable and flexible. Apply the following improvements to your code so it does the following:

  1. Ask the user for the required budget. (In HW2, we assumed that it takes $3,000 to travel to a solar eclipse. Some people would like to buy camera and gear, so we want them to define their own required budget)          
  2. Ask the user to input their daily savings rate starting from 1-1-2018.
  3. Ask the user to input their initial savings. (How much money you start with on 1-1-2018. Note that you started with a balance of zero dollars in the past homework.)
  4. Using loops and if statements, identify all future total solar eclipse events that you will be able to afford to go to.

Test your code using these parameters:

  • Required budget= $4000
  • Daily Savings (starting from January 1st 2018= $4
  • Initial savings= $200

How many eclipse events can you choose to attend out of the next 6 upcoming eclipses?

  1. [Extra credit +25pts] Using an if statement, adjust your program to print an appropriate response if the savings budget won’t allow you to attend any of the upcoming eclipses. Note if you did this in the Comment for grader box.

Self check: the output should look like this:

With a required budget of $4000, you can attend the following total solar eclipse(s):

A total solar eclipse that occurs at 10xx days with a savings balance of $4x1x

A total solar eclipse that occurs at 14xx days with a savings balance of $5xx6

A total solar eclipse that occurs at 1xxx days with a savings balance of $7xx8

A total solar eclipse that occurs at 2xxx days with a savings balance of $9xx0

A total solar eclipse that occurs at 3x4x days with a savings balance of $12xxx

Solutions

Expert Solution

ANSWER:

I have provided the properly commented and indented code so you can easily copy the code as well as check for correct indentation.
I have provided the output image of the code so you can easily cross-check for the correct output of the code.
Have a nice and healthy day!!

CODE

% a. Ask the user for the required budget. using input function,
budget = input("Please enter your own budget: ");

% b. Ask the user to input their daily savings rate starting from 1-1-2018.
saving = input("Please enter your daily saavings rate(starting from 1-1-2018): ");

% c. Ask the user to input their initial savings
ini_saving = input("Please enter your initial savings(on 1-1-2018): ");

% d. Future total solar eclipse events that you will be afford to go to
% As not provided, defining own solar eclipse events with required budgets
% defining vector of days after solor eclipse event will fall from 1-1-2018
days_after = [100,200,300,400,500,600];
% required budget to travel
req_budget = [400,900,1700,1800,2300,2500];

% looping for each event and checking if user can attend the event or not
% defining counter to record no. of events user can attend
events = 0;
for i=1:6
    day = days_after(i);
    required_bud = req_budget(i);
    
    % calculating saving of user till date
    saving_till_event = ini_saving + day*saving;
    
    % checking if saving fullfill required_bud
    if saving_till_event>= required_bud
        % user can attend the event
        % incrementing even t counter by 1
        events = events+1;
    end
end

% displaying result
fprintf("With a initial saving of $%d and per day saving of $%d, user can attend %d events.\n",ini_saving,saving,events);

OUTPUT IMAGE


Related Solutions

This is a Matlab Exercise problem. Please create the Matlab code and figure for the following...
This is a Matlab Exercise problem. Please create the Matlab code and figure for the following problem using problem specifications: Plot x vs y when y=sin(x), y=cos(x), y=sin (2*x), and y=2*sin(x) when x = 1:0.1:10. Use 2 by 2 subplot, sin(x) is in location 1, cos(x) is in location 2, sin(2*x) is in location 3 and 2*sin(x) is in location 4. The plot should have: (1) x label = ‘x value’, y label = ‘y value’, legend ‘y=sin(x)’,’ y=cos(x)’,’ y=sin...
Please Use Matlab to do this problem: The cross-sectional area measurements (??2) from 7 cells are...
Please Use Matlab to do this problem: The cross-sectional area measurements (??2) from 7 cells are as follows: ? = [153.3 91.2 99.3 115.0 101.7 135.8 102.4 ] Assuming the cross-sectional areas of the cells are normally distributed, construct a two-sided 95% confidence interval for the mean cross-sectional area of the entire batch. Then, generate one figure: Plot all 7 data points on x-axis, mark them with red circles; Plot the mean value, which is going to be the center...
Please answer 2 and 3. I have the answer for 1. A firm's total cost function...
Please answer 2 and 3. I have the answer for 1. A firm's total cost function is given by the equation: TC = 4000 + 5Q + 10Q2. (1) Write an expression for each of the following cost concepts: a. Total Fixed Cost b. Average Fixed Cost c. Total Variable Cost d. Average Variable Cost e. Average Total Cost f. Marginal Cost (2) Determine the quantity that minimizes average total cost and minimizing average variable cost. (3) Why does its...
Please Answer the following problem 1 and 2. write clearly. PROBLEM 1 A 5.96 − kg...
Please Answer the following problem 1 and 2. write clearly. PROBLEM 1 A 5.96 − kg block is placed against a compress spring on a frictionless 27.0 degrees incline. The spring, whose force constant is 2.5 N/cm, is compressed 21.3 cm, after which the block is released. How far up the incline will the block go before coming to rest? Measure the final position of the block with respect to its position just before being released. Consider two cases: (a)...
PLEASE SOLVED THIS PROBLEM BY HAND AND IN MINITAB: The following data are direct solar intensity...
PLEASE SOLVED THIS PROBLEM BY HAND AND IN MINITAB: The following data are direct solar intensity measurements (watts/m²) on different days at a location in southern Spain: 562, 869, 708, 775, 775, 704, 809, 856, 655, 806, 878, 909, 918, 558, 768, 870, 918, 940, 946, 661, 820, 898, 935, 952, 957, 693, 835, 905, 939, 955, 960, 498, 653, 730, and 753. Calculate the sample mean and sample standard deviation. Prepare a dot diagram of these data. Indicate where...
This is an intro to java question. Please answer with pseudocode and code. Problem 2: RSA...
This is an intro to java question. Please answer with pseudocode and code. Problem 2: RSA Public Key (10 points) (Cyber Security) RSA is an asymmetric encryption scheme, where a public key is used to encrypt data and a different, private key decrypts that data. RSA public/private keys are generated from two prime numbers, typically very large ones. The idea behind RSA is based on the fact that its difficult to factorize very large integers. RSA public key generation is...
Please answer the problem below Subu Motors has total capital of $200 million, consisting of 40%...
Please answer the problem below Subu Motors has total capital of $200 million, consisting of 40% debt (costing 5% before taxes) and 60% equity (costing 9%). Subu’s EBIT is $30 million and the tax rate is 30%. Estimate Subu’s EVA (Economic Value Added). (Enter your answer to the nearest $0.1 million. Leave the $ sign off. In other words, if your answer is $55.55 million, enter 55.6 for your answer. If your answer is negative, be sure to include a...
Explain at least three characteristics of the Sun that contribute to its solar activity. (Please answer...
Explain at least three characteristics of the Sun that contribute to its solar activity. (Please answer in your own words and type answer, thanks).
Problem 2: Speeding in a construction zone Please type the answer. Thank you. A group of...
Problem 2: Speeding in a construction zone Please type the answer. Thank you. A group of Brigham Young University—Idaho students collected data on the speed of vehicles traveling through a construction zone on a state highway, where the speed was 25 mph. The recorded speed (in mph) of 14 randomly selected vehicles is given below: 20,24,27,28,29,30,32,33,34,36,38,39,40,40 Assuming speeds are approximately normally distributed, construct a 95% confidence interval for the true mean speed of drivers in this construction zone. Interpret the...
Problem set 2: use the following table to answer questions 4-7 (40 pts total): # of...
Problem set 2: use the following table to answer questions 4-7 (40 pts total): # of children Frequencies 0 472 1 218 2 175 3 320 4 187 5 128 6 47 7 33 8 20 N 1,600 Please find the mean for numbers of children in this distribution (20 pts). # of children Frequencies How many # of children in each category: # of Children * Freq. in each column 0 472 0*472=0 1 218 2 175 3 320...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT