The solution to question 4 along with required details in comments are given as follows:
----------------------- MAIN SCRIPT FILE
clear all
clc
f=@(x) sin(x); % a sample function
want_to_continue=1;
while (want_to_continue)
% Menu used for switch satements
fprintf('\n\nPlease enter one among the following choices to select
the operation to be performed:');
fprintf('\n1. Find muliple zeros');
fprintf('\n2. Find multiple maxima');
fprintf('\n3. Find multiple minima');
fprintf('\n4. Find Area under curve');
fprintf('\n5. Want to exit?');
num=input('\nEnter the choice:');
switch(num)
case 1 % find N zeros
N=input('\nFind the number of zeros to be found:');
roots=find_multiple_zeros(f,N); % call the function
g=sprintf('%3.5f ',roots); % display the statement
fprintf('The Roots of the function are obtained obtained at
:%s\n',g);
case 2 % find N minimas
N=input('\nFind the number of minima(s) to be found:');
roots=find_multiple_minima(f,N); % call the function
g=sprintf('%3.5f ',roots); % display the results
fprintf('The minima of the function are obtained at
:%s\n',g);
case 3 % find N maximas
N=input('\nFind the number of maxima(s) to be found:');
roots=find_multiple_maxima(f,N); % call the function
g=sprintf('%3.5f ',roots); % display the results
fprintf('The maxima of the function are obtained at
:%s\n',g);
case 4
N1=input('\n Enter the first limit:'); % find the lower limit of
the curve
N2=input('\n Enter the second limit:'); % find the upper limit of
the curve
M=input('\n Enter 1 for trapz method and 2 for quad method:'); %
select the method
area=find_aoc(f,N1,N2,M); % call the function
fprintf('The area of the function between %d and % d is %3.5f sq.
units.\n',N1,N2,area);
case 5
want_to_continue=0;
otherwise
fprintf('Wrong Choice entered!')
end
end
-------------------------- FUNCTION 1: FIND MULTIPLE ZEROS
function roots=find_multiple_zeros(f,N)
% find N zeros of the function
starting_points=linspace(0,N*pi,100); % divide the interval
betweeen 0 and N*pi into 100 pieces
for i=1:1:100
% Look for the zeros in the function's current interval.
x(i)=fzero(f, starting_points(i));
end
x_unique=x(diff(x)>1e-12); % identify unique zeros
roots=x_unique; % return unique zeros
end
------------------------ FUNCTION 2: FIND MULTIPLE MINIMAS
function roots=find_multiple_minima(f,N)
starting_points=linspace(0,2*(N+1)*pi,(N+1)); %divide the interval
betweeen 0 and 2*(N+1)*pi into (N+1) pieces
for i=1:1:N
% Look for the minima in the function's suninterval.
x(i)=fminbnd(f,starting_points(i),starting_points(i+1));
end
x_unique=x;
roots=x_unique; % return the minimas
end
-------------------------- FUNCTION 3: FIND MULTIPLE MAXIMA
function roots=find_multiple_maxima(f,N)
starting_points=linspace(0,10*(N+1)*pi,10*(N+1));
h=@(x)-f(x); % negate the function to convert to maxima
problem
for i=1:1:N
% Look for the zeros in the function's current subintervals
x(i)=fminbnd(h,starting_points(i),starting_points(i+1));
end
x_unique=x;
roots=x_unique(1:N); % return the maximas
end
----------------------------------- FUNCTION 4: FIND AREA UNDER CURVE
function area=find_aoc(f,N1,N2,M)
x=linspace(N1,N2,1000)';
h=@(x) abs(f(x));
% remove the sign from the function so that all y values are
positive. This is to
% ensure that area obatined is always positive
if M==1 % if method selected is one, use trapezoidal
method
area = trapz(x,h(x));
elseif M==2 % if method selected is two, use quad method
area= quad(h,N1,N2);
else
area=0; % othewise, return 0
end
end
--------------------------- SCREENSHOTS OF CODES
-------------------------------------- SAMPLE OUTPUT
I only need help on doing number 4 LON-CAPA COurse ConSSOE-First ear-SprirASSGT9 (1)pd softEdge elackboard Conter...
NEED HELP with HTML with Javascript embedding for form validation project below. I have my code below but I'm stuck with validation. If anyone can fix it, I'd really appreciate. ****************************************************************************** CODE: <!DOCTYPE html> <!-- To change this license header, choose License Headers in Project Properties. To change this template file, choose Tools | Templates and open the template in the editor. --> <html> <head> <title>Nice</title> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <script> var textFromTextArea; function getWords(){ var text =...
could you please help me with this problem, also I need a little text so I can understand how you solved the problem? import java.io.File; import java.util.Scanner; /** * This program lists the files in a directory specified by * the user. The user is asked to type in a directory name. * If the name entered by the user is not a directory, a * message is printed and the program ends. */ public class DirectoryList { public static...
Please!!! need help asap!!!! write a C++program to analyze a small subset of the data that has been collected. See file universities.txt .Use precisely seven parallel arrays: one for name of university, one for state, one for city, one for yearly tuition, one for enrollment, one for average freshman retention, and one for the percent of students who graduate with in six years. Note that the percentage of student accepted is not stored.An output file is opened in main() and...
matlab help *****CONSTANT***** NUM_MONTHS = 12; FIRST_YEAR = 2013; LAST_YEAR = 2016; %*****INPUT***** months = 1:NUM_MONTHS; years = FIRST_YEAR:LAST_YEAR; % read data file lake_powell = load( 'lake_powell.txt' ); % OR load lake_powell.txt % print with title and year column headings. fprintf(' Lake Powell Water Levels (in feet)\n') fprintf('%8d ', years) fprintf('\n') % print contents of lake_powell for month = 1:NUM_MONTHS fprintf('%9.2f', lake_powell(month,:)) fprintf('\n') end % PART B ========================================================== fprintf('\nPART B: Determine average elevation of water level for each year and...
I need help making this work correctly. I'm trying to do an array but it is drawing from a safeInput class that I am supposed to use from a previous lab. The safeInput class is located at the bottom of this question I'm stuck and it is not printing the output correctly. The three parts I think I am having most trouble with are in Bold below. Thanks in advance. Here are the parameters: Create a netbeans project called ArrayStuff...
Program 7 File Processing and Arrays (100 points) Overview: For this assignment, write a program that will process monthly sales data for a small company. The data will be used to calculate total sales for each month in a year. The monthly sales totals will be needed for later processing, so it will be stored in an array. Basic Logic for main() Note: all of the functions mentioned in this logic are described below. Declare an array of 12 float/doubles...
i need help with a mips program to to covert roman numerals to real numbers Lab 4: Roman Numeral Conversion Part A: Due Sunday, 19 May 2019, 11:59 PM Due Friday, 24 May 2019, 11:59 PM Part B: Minimum Submission Requirements Ensure that your Lab4 folder contains the following files (note the capitalization convention): o Diagram.pdf o Lab4. asm O README.txt Commit and push your repository Lab Objective In this lab, you will develop a more detailed understanding of how...