Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Using the first code please trying and put it into matlab using the template below so it can work. I just want to check if

Using the first code please trying and put it into matlab using the template below so it can work. I just want to check if im doing it right. image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
% Name: % Date: ANSWER: % CMPSC 200 %FUNCTION Definations function print_splash_screen() %calling get_data() function to extract user data; [area,c_curved, c_straight]=get_data(); % calling anonymous function for radius and minimum cost [radius, min_cost]=Min_cost_and_optimal_radius_calculator(area,c_curved.c_straight); % calling function which calculate length according to above data [length]=calc_length(area, radius); % And finally printing them print_results (area, radius, length, min_cost) end % function that will get data from user function (area, c_curved.c_straight]=get_data() % assumed user data area, change it if required area=5; %assumed user data c_curved change it if required c_curved=2; % assumed user data c_straight, change it if required c_straight=9; end % function that will calculate minimum cost and optimal radius function [Roptimal,min_cost]=Min_cost_and_optimal_radius_calculator(area.c_curved.c_straight) % Cost function C(RA) according to handout fun=@(R)(((c_straight/(2*R))*((4*R^2)+(2area)-(pi*R^2}))+(c_curved*piR)); x1=0.5; % initial value x2=5000;%final value % calculating Roptimal and min_cost using fminbnd [Roptimal, min_cost]=fminbnd(fun,x1,x2); end %function to calculate length using optimal radius and area function [length]=calc_length(area, radius) % Length equation according to handout length=(area/(2* radius))-(pieradius)/4; % printing function which will show all the required results function print_results(area, radius, length, cost) fprintf('Area is %d 'area) fprintf('Optimal radius is %d ', radius) fprintf("Minimum cost is %d ', cost) fprintf("Length is %d ', length) end end function project_60) % PROJECT_6 project_60) Calculates the optimal dimensions of retention basin 8 Remember to customize the name of the project (use your own initials) and add 8 any comments that will help someone understand your program. 8 All multiplications, divisions, and exponentiations must use the dot operator. % All code should be tabbed in once (as the template shows) and aligned I recommend that you download this template and use it directly. Name: Date: CMPSC Print the splash screen by calling the print_splash_screen function This is a single functon call - DO NOT HAVE ANY fprintf STATEMENTS HERE Call the get_data function that has the user enter the inputs There are three inputs in the output list, area, cost_curved and cost_straight. There are no values passed to the get_data function % This is a single functon call - DO NOT HAVE ANY input STATEMENTS HERE Create an anonymous function for the cost using the equation on the handout has cost as a function of area and radius only. The start of it will have the function name and the variable list. % Depending upon your variable names it might start as cost = @(r) followed % by the calculation for the cost using just area and radius % Pass your cost function to fminbnd using a range of 0.1 to 5000. This function needs to have two return values. The first is the optimal radius and the second is the minimum cost Call the function that calculates the length of the straight sides passing the % area and the optimal radius to this function Print the results by passing the area, the radius, the length, and the minimum cost to a print_results function This is a single line function call end % Function Definitions function print splash_screen (progDate, desc) end function (area, c_curved, c_straight] = get_data() % end function [length] = calc_length(area, radius) op op end function print_results(area, radius, length, cost) op op do end % Name: % Date: ANSWER: % CMPSC 200 %FUNCTION Definations function print_splash_screen() %calling get_data() function to extract user data; [area,c_curved, c_straight]=get_data(); % calling anonymous function for radius and minimum cost [radius, min_cost]=Min_cost_and_optimal_radius_calculator(area,c_curved.c_straight); % calling function which calculate length according to above data [length]=calc_length(area, radius); % And finally printing them print_results (area, radius, length, min_cost) end % function that will get data from user function (area, c_curved.c_straight]=get_data() % assumed user data area, change it if required area=5; %assumed user data c_curved change it if required c_curved=2; % assumed user data c_straight, change it if required c_straight=9; end % function that will calculate minimum cost and optimal radius function [Roptimal,min_cost]=Min_cost_and_optimal_radius_calculator(area.c_curved.c_straight) % Cost function C(RA) according to handout fun=@(R)(((c_straight/(2*R))*((4*R^2)+(2area)-(pi*R^2}))+(c_curved*piR)); x1=0.5; % initial value x2=5000;%final value % calculating Roptimal and min_cost using fminbnd [Roptimal, min_cost]=fminbnd(fun,x1,x2); end %function to calculate length using optimal radius and area function [length]=calc_length(area, radius) % Length equation according to handout length=(area/(2* radius))-(pieradius)/4; % printing function which will show all the required results function print_results(area, radius, length, cost) fprintf('Area is %d 'area) fprintf('Optimal radius is %d ', radius) fprintf("Minimum cost is %d ', cost) fprintf("Length is %d ', length) end end function project_60) % PROJECT_6 project_60) Calculates the optimal dimensions of retention basin 8 Remember to customize the name of the project (use your own initials) and add 8 any comments that will help someone understand your program. 8 All multiplications, divisions, and exponentiations must use the dot operator. % All code should be tabbed in once (as the template shows) and aligned I recommend that you download this template and use it directly. Name: Date: CMPSC Print the splash screen by calling the print_splash_screen function This is a single functon call - DO NOT HAVE ANY fprintf STATEMENTS HERE Call the get_data function that has the user enter the inputs There are three inputs in the output list, area, cost_curved and cost_straight. There are no values passed to the get_data function % This is a single functon call - DO NOT HAVE ANY input STATEMENTS HERE Create an anonymous function for the cost using the equation on the handout has cost as a function of area and radius only. The start of it will have the function name and the variable list. % Depending upon your variable names it might start as cost = @(r) followed % by the calculation for the cost using just area and radius % Pass your cost function to fminbnd using a range of 0.1 to 5000. This function needs to have two return values. The first is the optimal radius and the second is the minimum cost Call the function that calculates the length of the straight sides passing the % area and the optimal radius to this function Print the results by passing the area, the radius, the length, and the minimum cost to a print_results function This is a single line function call end % Function Definitions function print splash_screen (progDate, desc) end function (area, c_curved, c_straight] = get_data() % end function [length] = calc_length(area, radius) op op end function print_results(area, radius, length, cost) op op do end

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

Google-ITA 2. What were the arguments of DOJ to block this merger?

Answered: 1 week ago

Question

10:16 AM Sun Jan 29 Answered: 1 week ago

Answered: 1 week ago