Question

In: Computer Science

Please Use matlab and show command window. Please go through all steps Using a Dialog button...

Please Use matlab and show command window. Please go through all steps

Using a Dialog button with 3 buttons have the user chose one of the 3 anonymous functions below to be used in the later selected three Programmed functions (1) Integral by Trapezoidal Method,(2) Integral by Simpson Method, or (3) Root by BiSection Method.:

a. f(x) = 2*x^5 -3*x^2 – 5

b. f(x) = x^2 – 5

c. f(x) = x^(1/2)

2. Using an input statement ask the user to pick Midpoint, Simpson, or ROOT. Make sure you are consistent with string or number. You can use what you are comfortable with. The input variable will then be used in a switch case statement. Each case will do the following

a. First case (Midpoint Integral) i. Ask for the three inputs a, b, and n ii. Call the function iii. Use fprintf to output the answer

b. Second case (Simpson Integral) i. Ask for the three inputs a, b, and n ii. Call the function iii. Use fprintf to output the answer

c. Third case (ROOTs) i. Ask for the three inputs a, b, and epsilon the convergence limit ii. Call the function iii. Use fprintf to output the answer

Solutions

Expert Solution

function result = Midpoint(f, a, b, samples)

x = linspace(a,b,samples);

dx = (a-b)/samples;
result = 0;
for i = 1:samples
  
    result = result + f(x(i) + dx)*dx;
end
end


function result = Simpson(f,a,b, samples)

dx = (b-a)/samples;

x= linspace(a,b,samples);

result = 0;

for i = 1:samples
    if i == 1
        result = result + f(x(i));
    else
        if mod(i, 2) == 0
          
            result = result + 4 * f(x(i));
    else
       result = result + 2 * f(x(i));
        end
  
  
    end


end
result = dx / 3 * result;
end


function result = BiSection(f, a, b, epsilon)
  
    t = (a+b)/2;
  
    while (f(t) > epsilon)
      
        if f(t)*f(b) < 0
          
            a = t;
        else
            if f(t) * f(a) < 0
             b = t;
            end
          
        end
        t= (a + b)/2;
      
    end

    result = t;
end


clc
clear

f1 = @(x) 2*x^5 - 3*x^2 - 5;

f2 = @(x) x^2 - 5;

f3 = @(x) x^(1/2);


disp(spaces(10) + "Your choices: ")
disp("Midpoint" + spaces(5) + "Simpson" + spaces(5) + "Bisection")

choice = input();

if (choice == "Midpoint")
    a = input("Input value of a: ", "s");
    a = str2double(a);
  
    b = input("Input value of b: ", "s");
    b = str2double(b);
  
    c = input("Input value of n(number of samples): ", "s");
    c= str2double(c);
  
    result = Midpoint(f1, a, b, n);
    result1 = Midpoint(f2, a, b, n);
    result3 = Midpoint(f3, a, b, n);
  
    disp("Value of integral of 2*x^5 - 3*x^2 - 5 within "+a+" and "+b+" is "+ result)
  
    disp("Value of integral of x^2 - 5 within "+a+" and "+b+" is "+ result1)
  
    disp("Value of integral of x^(1/2) within "+a+" and "+b+" is "+ result2)
  
else
    if choice == "Simpson"
      
    a = input("Input value of a: ", "s");
    a = str2double(a);
  
    b = input("Input value of b: ", "s");
    b = str2double(b);
  
    c = input("Input value of n(number of samples): ", "s");
    c= str2double(c);
  
    result = Simpson(f1, a, b, n);
    result1 = Simpson(f2, a, b, n);
    result3 = Simpson(f3, a, b, n);
  
    disp("Value of integral of 2*x^5 - 3*x^2 - 5 within "+a+" and "+b+" is "+ result)
  
    disp("Value of integral of x^2 - 5 within "+a+" and "+b+" is "+ result1)
  
    disp("Value of integral of x^(1/2) within "+a+" and "+b+" is "+ result2)
      
    else
    a = input("Input value of a: ", "s");
    a = str2double(a);
  
    b = input("Input value of b: ", "s");
    b = str2double(b);
  
    epsilon = input("Input value of epsilon: ", "s");
    epsilon= str2double(epsilon);
  
    result = BiSection(f1, a, b, epsilon);
    result1 = BiSection(f2, a, b, epsilon);
    result3 = BiSection(f3, a, b, epsilon);
  
    disp("Value of integral of 2*x^5 - 3*x^2 - 5 within "+a+" and "+b+" is "+ result)
  
    disp("Value of integral of x^2 - 5 within "+a+" and "+b+" is "+ result1)
  
    disp("Value of integral of x^(1/2) within "+a+" and "+b+" is "+ result2
    end
end


Related Solutions

Commands are to be typed in the Command Window in MATLAB [Those preceding the symbol>> are...
Commands are to be typed in the Command Window in MATLAB [Those preceding the symbol>> are the commands] 16.3 Matrix operations >>a=[1 2 3;4 5 6;7 8 9] >>b=[1 0 0;1 0 1;0 0 1] Assigning: >>a=b(2,:) Transposing: >>[1;2;3] >>[1;2;3]' Incrementing: >>Tempk=a+273.15 Scaling: >>L=a*2.5 Adding & subtracting: >>[1 2 3;4 5 6]-[8 7 6;4 2 0] Repeating: >>sqrt(a) >>sqrt(b) Operating term by term: >>[1 3;5 8].*[0 1;4 2] >>[1 3;5 8]*[0 1;4 2] Creating matrix efficiently >>m=[364;297]; >>n=[3,6,4;2,9,7]; >>p(1,1)=3; >>q=[2:2:200]...
Please use minitab, and show the steps to get to the solution. Meaning: Go to Stat,...
Please use minitab, and show the steps to get to the solution. Meaning: Go to Stat, basic statistics, etc, etc. Forty sewage samples a waste water treatment plant were collected from a recent EPA report. The ppm of suspended solids in each specimen is presented in the following table. (a) Examine descriptive statistics of the mean, median, standard deviation, first quartile, third quartile, minimum value, and maximum value. What do these statistics indicate about the shape of the population distribution?...
Section 1.0: MATLAB Fundamentals Step 1.1 Open the MATLAB application Step 1.2 In the Command Window,...
Section 1.0: MATLAB Fundamentals Step 1.1 Open the MATLAB application Step 1.2 In the Command Window, type the following: x=8 % percentage sign denotes comment y=9 % variable y set to 9 x+y % add variable x + y clear %clears the workspace window clc % clears the command window Note: the % sign indicates a user comment. In the Command Window, you should see your answer : ans=17 In the Workspace window, observe "ans", "x" and "y" Step 1.3...
Write the line x = 0:2:20; in the Command Window of MATLAB and then create a...
Write the line x = 0:2:20; in the Command Window of MATLAB and then create a Simulink model that first loads x from the Workspace, then creates a vector y such that y = 2.5x + ex , and finally sends the vector y back to the Workspace. You will need a From Workspace block, a To Workspace block, two Constant blocks, a Product block, and a Sum block. Note that there is a sample time associated with the From...
Open the Command Prompt window and use the nslookup command to identify the domain names that...
Open the Command Prompt window and use the nslookup command to identify the domain names that correspond to the following IP addresses: 161.170.244.20 205.251.242.103 144.160.155.43 Use the Command Prompt window and nslookup command to identify the IP addresses that correspond to the following domain names: walmart.com amazon.com att.com Close the Command Prompt window. Submit your findings.
Please answer all parts of the question. Please show all work and all steps. 1a.) Show...
Please answer all parts of the question. Please show all work and all steps. 1a.) Show that the solutions of x' = arc tan (x) + t cannot have maxima 1b.) Find the value of a such that the existence and uniqueness theorem applies to the ivp x' = (3/2)((|x|)^(1/3)), x(0) = a. 1c.) Find the limits, as t approaches both positive infinity and negative infinity, of the solution Φ(t) of the ivp x' = (x+2)(1-x^4), x(0) = 0
NOT using Excel, please show all steps. A bank is planning to install a new computerized...
NOT using Excel, please show all steps. A bank is planning to install a new computerized accounts system. Bank management has determined the activities required to complete the project, the precedence relationships of the activities, and activity time estimates as follows: NOT using Excel, please show all steps. Activity Description Predecessor a m b a Position recruiting — 5 8 17 b System development — 3 12 15 c System training a 4 7 10 d Equipment training a 5...
Please show all steps using data set below and excel. By using a bivariate regression trend...
Please show all steps using data set below and excel. By using a bivariate regression trend line model, forecast total houses sold for the next five years. Prepare a time series plot of these data (years are on the x axis, THS is on the y axis) that shows both actual and forecast THS for the next five years. Total Houses Sold Year Northeast 1996         74.00 1997         78.00 1998         81.00 1999         76.00 2000         71.00 2001...
***PLEASE SHOW ALL ANSWERS, FORMULAS, STEPS DONE THROUGH EXCEL!!!*** Joey is on a diet. Daily, she...
***PLEASE SHOW ALL ANSWERS, FORMULAS, STEPS DONE THROUGH EXCEL!!!*** Joey is on a diet. Daily, she needs three dietary supplements, A, B and C as follows: at least 32 units of A, 30 units of B, and 40 units of C. These can be found in either of two marketed products Squabb I and Squabb II. The Squabb I pill cost $1.50 and the Squabb II pill costs $12.25. How many of each pill should Joey buy to satisfy her...
Write a MATLAB script file to integrate  using trapezoid method (do not use trapz command for this...
Write a MATLAB script file to integrate  using trapezoid method (do not use trapz command for this part, write your own script). Consider x=-0.5 to 3 with Δt=0.01, and compare your result with using “integral” and "trapz" commands (all in one file).
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT