Question

USING MATLAB Write a program called QuadProg that determines the roots of a quadratic equation. Use...

USING MATLAB

Write a program called QuadProg that determines the roots of a quadratic equation. Use functions to implement each action. Zip you directory of *.m files into a single file and turn this in on BBLearn under Class Activities.

QuadProg

  • write a function called getInputs to get a single input value.
  • write a function called findDiscriminant
  • write a function called findDenominator
  • write a function called findRoot
    • which will be used for both roots
  • write a function called displayResults

displayResults should have two inputs: displayResults(string, value);

max_of_two=getLargerOfTwo(A,B);

str1='max of A and B is';

displayResults(str1,max_of_two);

isEven/isOdd

Write these two functions that determine if the inputs to the QuadProg are even or odd.

  • write a function called isEven
  • write a function called isOdd
  • Reuse displayResults to show the results.

Now update the QuadProg program to report:

  • has no roots - imaginary
  • has one root
  • has two roots
  • Reuse displayResults to show the results.

getLargerOfTwo

Write a function that gets 3 inputs and then finds the max of two numbers and reuse the same function to get the max of 3 numbers. Put this code below the Quadratic code.

  • reuse getInputs to get 3 values.
  • write a function getLargerOfTwo
  • Then use the same function getLargerOfTwo to create a getLargestOfThree function
  • Reuse displayResults to show the results.

Homework Answers

Answer #1

:: Solution ::

function inpvalue = getInput()
    inpvalue = input("Please enter value:");
end
function discriminant = getDiscriminant(a,b,c)
    discriminant = b*b - (4*a*c);
end
function Denominator = findDenominator(a)
     Denominator = 2*a;
end
function [root1,root2] = findRoot(Denominator,discriminant,b)
     root1 = -1*b + sqrt(discriminant);
     root1 = root1/Denominator;
     root2 = -1*b - sqrt(discriminant);
     root2 = root2/Denominator;
end
function displayResults()
    a = getInput();
    b = getInput();
    c = getinput();
    discriminant = getDiscriminant(a,b,c);
    Denominator = findDenominator(a);
    root1,root2 = findRoot(Denominator,discriminant,b);
    disp(root1);
    disp(root2);
    if(root1 > root2)
        disp(root1)
    else
        disp(root2)
    end
end

Please rate my answer.Thank you...

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Write a C++ programming code for a non-zero, discuss the roots of the quadratic equation as...
Write a C++ programming code for a non-zero, discuss the roots of the quadratic equation as follows: a) D =0; the equation has a double solution.      x1 = x2 = -b/2a b) D>0; the question has two different solutions x1 and x2.      x1= (-b-sqrt(D))/2a      x2= (-b+sqrt(D))/2a c) if D<0; the equation has no real solution
using matlab please present code for the following (ALL PARTS PLEASE AND THANK YOU) 1. No...
using matlab please present code for the following (ALL PARTS PLEASE AND THANK YOU) 1. No Input/No Output Write a function that has no input and no outputs. This function will simply display some text when it is called. (this is my code, are there suggestions for improvements?) function Display() disp('some text') end 2. 1 Input/No Outputs Write a function with one input and no outputs. This function will simply display a variable that is provided as an input argument....
Write spim program and execute it on mars. Your program reads two integer values x and...
Write spim program and execute it on mars. Your program reads two integer values x and y. Write a function called sum that gets x and y passed as parameters and return the sum of odd values between x and y inclusive. In addition write another function called even that gets x and y as parameters and returns the count of all even numbers between x and y inclusive. Also in main print the quotient and remainder of diving y...
Write a function called char_counter that counts the number of a certain character in a text...
Write a function called char_counter that counts the number of a certain character in a text file. The function takes two input arguments, fname, a char vector of the filename and character, the char it counts in the file. The function returns charnum, the number of characters found. If the file is not found or character is not a valid char, the function return -1. As an example, consider the following run. The file "simple.txt" contains a single line: "This...
IN PYTHON Menu: 1. Hotdog. ($2) 2. Salad ($3)  3. Pizza ($2) 4.Burger ($4) 5.Pasta ($7) Write...
IN PYTHON Menu: 1. Hotdog. ($2) 2. Salad ($3)  3. Pizza ($2) 4.Burger ($4) 5.Pasta ($7) Write a menu-driven program for  Food Court. (You need to use functions!) Display the food menu to a user . 5 options Use numbers for the options and for example "6" to exit. Ask the user what he/she wants and how many of it. (Check the user inputs) AND use strip() function to strip your inputs(if needed) Keep asking the user until he/she chooses the exit...
Task 2: Compare strings. Write a function compare_strings() that takes pointers to two strings as inputs...
Task 2: Compare strings. Write a function compare_strings() that takes pointers to two strings as inputs and compares the character by character. If the two strings are exactly same it returns 0, otherwise it returns the difference between the first two dissimilar characters. You are not allowed to use built-in functions (other than strlen()) for this task. The function prototype is given below: int compare_strings(char * str1, char * str2); Task 3: Test if a string is subset of another...
Hello! I am confused on the code for this question. Write a complete Python function called...
Hello! I am confused on the code for this question. Write a complete Python function called Frog, with two integer parameters M and N, where N has the default value of 5. The function computes and returns one of two results: if N is odd it returns the equation 2 * M + N, but if it is even it returns the equation 3 * M - N instead.
PROGRAM PYHTON Write a function called "calculateInput" that when called, it asks the user to enter...
PROGRAM PYHTON Write a function called "calculateInput" that when called, it asks the user to enter an number. Then, it asks for a second number. These will use the "input" command. Store these as two separate variables. This function takes NO arguments and is also a VOID function, there is no return statement. The function should print the result of these two numbers multiplied together. The program should be able to multiply floats. For example: Test Input Result calculateInput() 5...
Assignment #4 – Student Ranking : In this assignment you are going to write a program...
Assignment #4 – Student Ranking : In this assignment you are going to write a program that ask user number of students in a class and their names. Number of students are limited to 100 maximum. Then, it will ask for 3 test scores of each student. The program will calculate the average of test scores for each student and display with their names. Then, it will sort the averages in descending order and display the sorted list with students’...
Using nested loops, write a function called primes(a,b) that takes in two positive integers a and...
Using nested loops, write a function called primes(a,b) that takes in two positive integers a and b (where a<b). Then simply RETURNS a string containing all the prime numbers between a and b (or if there are none, the string "No Primes"). You should check that a and b are valid inputs, that is, that a and b are integers such that a<b (otherwise, the function should print “No Primes”). Three sample calls of your function (in IDLE) should produce...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT