Question

isplays l itnuml is less than num2. 2. (50+30- 80 Points) Write a MATLAB function numcomp502 (numl, num2) that takes two numbers numl and as input and returns num3 as output, such that num3 is equal to 0, 1, and-1 depending on whether numl is equal to, greater than or less than num2 respectively. Test your code with the pairs (10, 5), (-3,-3), and (2, 10) as input. Attach a screen-shot. 3. 80 Points Write a matlab function myquad (a, b, c) that returns the roots of a quadratic equation ax2+ bx + c 0. The algorithm you need to use: Test whether the equation is a true quadratic or not by checking whether a is non- zero. If a . 0, (the equation is not a true quadratic) two situations exist o If b o Else, we have a case with a single root r-c/b . 0, it is the case of a trivial solution If aヂ0, three situations exist depending on the value of the discriminant, d b2-4ac, · o If d 0, we have two equal real roots o lf d > 0, we have two unequal real roots o If d < 0, we have two imaginary roots In all cases display an appropriate message and the values of the roots on the terminal as well. . 4. 100 Points Write a function check504 (X) that takes a vector X as input and displays an error message on the terminal unless every element is nonzero. In cas message indicating error. You have the flexibility to define your messages. The example below e none of the element is zero, it will display another

Need help with number 3, thanks!

0 0
Add a comment Improve this question Transcribed image text
Answer #1
function [root1, root2]=myquad(a, b, c)
  if a!=0
    D=b^2-4*a*c;
    if D<0
        fprintf('\nThe equation has no real roots.\n\n') ;
        end
    elseif D==O
        root1=b/(2*a);
        root2=b/(2*a);
        fprintf('\nThe equation has one root,\n'); 
        fprintf(' %.3f\n\n',root1);
        end;
    else
        root1=(-b+sqrt(D))/(2*a);
        root2=(-b-sqrt(D))/(2*a);
        fprintf('\nThe equation has two roots,\n') ;
        fprintf(' %.3f and %.3f\n\n',root1,root2);
        end
  end
  else
    fprintf('\nThe equation is not a quadratic equation,\n');
  end
end
Add a comment
Know the answer?
Add Answer to:
Need help with number 3, thanks! isplays l itnuml is less than num2. 2. (50+30- 80...
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. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • write a C programming code for the following prompt. please use stucture concept and test if...

    write a C programming code for the following prompt. please use stucture concept and test if the code works perfectly. Project Description: In this project, you will write a program to calculate the roots of a quadratic equation. Structure concepts will be used in this project. Your program will prompt the user to enter the coefficients of a quadra coefficientsType. Then it will compute the roots of the quadratic equation and store the result in a structure variable of type...

  • A quadratic equation is generally represented as, ax^2 + bx + c The root(s) of the...

    A quadratic equation is generally represented as, ax^2 + bx + c The root(s) of the above quadratic equation is computed using the following formula, root1 = (-b + sqrt(D))/ 2a root2 = (-b - sqrt(D))/2a Where D is the discriminant of the quadratic equation and is computed as, D = b^2 - 4ac Given the value of D, the roots of a quadratic equation can be categorized as follows, D > 0 : Two distinct real roots D =...

  • In this homework, you will create a class that stores a list of transactions and computes...

    In this homework, you will create a class that stores a list of transactions and computes the average transaction for a given month. The user must input the name of the month and the transactions into the terminal. The Transaction_List Class First you will create two C++ files called abc1234_Transaction_List.h and abc1234_Transaction_List.cpp. Below is a UML class diagram that shows the basic design of the Transaction_List class. Transaction List -month : string transactions: vector-sdouble - num transactions: int +Transaction Listim...

  • Rule book: 1.)Must be Python - 2.) no imported module (ie cmath) - no can do...

    Rule book: 1.)Must be Python - 2.) no imported module (ie cmath) - no can do on the imports... pure code.. 3.) numbers are float - not integer. Here's the prompt: (Algebra: solve quadratic equations) The two roots of a quadratic equation ax^2 + bx + c = 0 can be obtained using the following formula: r1 = (-b + sqrt(b^2 - 4ac)) / (2a) and r2 = (-b - sqrt(b^2 - 4ac)) / (2a) b^2 - 4ac is called...

  • 2. The roots of the quadratic $a x^2 + b x + c$ are given by...

    2. The roots of the quadratic $a x^2 + b x + c$ are given by $$\frac{-b \pm \sqrt{b^2-4ac}}{2a}$$ If $b^2-4ac <0$, the quadratic has no real roots. Write a function to calculate the real roots of a quadratic. The function should have 3 arguments, *a*, *b* and *c*. If $b^2-4ac <0$, the function should print "quadratic has no real roots", and then return(NULL). Otherwise, the function should return a vector of length 2, those being the real roots (which...

  • Hello I need help with this program. Should programmed in C! Program 2: Sorting with Pointers...

    Hello I need help with this program. Should programmed in C! Program 2: Sorting with Pointers Sometimes we're given an array of data that we need to be able to view in sorted order while leaving the original order unchanged. In such cases we could sort the data set, but then we would lose the information contained in the original order. We need a better solution. One solution might be to create a duplicate of the data set, perhaps make...

  • C++ requirements The store number must be of type unsigned int. The sales value must be...

    C++ requirements The store number must be of type unsigned int. The sales value must be of of type long long int. Your program must properly check for end of file. See the section Reading in files below and also see your Gaddis text book for details on reading in file and checking for end of file. Your program must properly open and close all files. Failure to follow the C++ requirements could reduce the points received from passing the...

  • I need help creating program for the Test_Bisection pseudocode. I need to find a root for...

    I need help creating program for the Test_Bisection pseudocode. I need to find a root for each function f and g and get the output below. Pseudocode Now let's construct pseudocode to carry out this procedure. We shall not try to create a piece of high-quality software with many "bells and whistles,” but we write the pseudocode in the form of a procedure for general use. This allows the reader an opportunity to review how a main program and one...

  • Python GPA calculator: Assume the user has a bunch of courses they took, and need to...

    Python GPA calculator: Assume the user has a bunch of courses they took, and need to calculate the overall GPA. We will need to get the grade and number of units for each course. It is not ideal to ask how many courses they took, as they have to manually count their courses. Programming is about automation and not manual work. We will create a textual menu that shows 3 choices. 1. Input class grade and number of units. 2....

  • For Python-3 I need help with First creating a text file named "items.txt" that has the...

    For Python-3 I need help with First creating a text file named "items.txt" that has the following data in this order: Potatoes Tomatoes Carrots. Write a python program that 1. Puts this as the first line... import os 2. Creates an empty list 3. Defines main() function that performs the tasks listed below when called. 4. Put these two lines at the top of the main function... if os.path.exists("costlist.txt"): os.remove("costlist.txt") Note: This removes the "costlist.txt" file, if it exists. 5....

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT