Using matlab and if/else statement please!
%%%%%%%%%%%%%save this as cal_root.m
function [root1,root2]=cal_root(a,b,c)
d=b^2-4*a*c;
if(d>0)
root1=(-b-d^0.5)/(2*a);
root2=(-b+d^0.5)/(2*a);
if(root1>root2)
temp=root1;
root1=root2;
root2=temp;
end
elseif(d==0)
root1=-b/(2*a);
root2=NaN;
else
root1=NaN;
root2=NaN;
end
end
%%%%%%%%%%%%%%%end of file1
%%%%%start of file 2
[root1,root2]=cal_root(2,8,8);
fprintf('roots for 2x^2+8x+8=0\n');
disp(root1)
disp(root2)
[root1,root2]=cal_root(-5,3,-4);
fprintf('roots for -5x^2+3x-4=0\n');
disp(root1)
disp(root2)
[root1,root2]=cal_root(-2,7,4);
fprintf('roots for -2x^2+7x+4=0\n');
disp(root1)
disp(root2)
Using matlab and if/else statement please! Write a function that determines the real roots of a...
4-6 on matlab 4. Write a program in a script file that determines the real roots of a quadratic equation ax2+bx+c 0 When the file runs, it asks the user to enter the values of the constants a, b, and c. To calculate the roots of the equation the program calculates the discriminant D, given by: D b2-4ac When D 0, the program displays message "The equation has two roots," and the roots are displayed in the next line. When...
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...
#6 Write a Matlab program that finds numerically all the roots (or the zeros) of the algebraic equation below in the interval 1.0 <=x<=3.0: sqrt(log(x^2+1))=x^2*sin(e^x)+2 Part a) Prompt the user to enter a positive integer number n, defined the range 2<=n<=15, and then verify if the number entered lies within the specifications. Your program must allow the user to reenter the number without the need to rerun the program. Part b) Create a user-defined function for the bisection method(see details...
You are given the following function () 6a +11 6.1 You are to find the roots of this function using the secant method with z 2.5-and zi = 3.5 1.(6 points) Develop a function m-file that calculates the root of the above function using the secant method. The function should have the following five inputs only. 1. (2 points) The equation or function whose roots need to be found 2.(2 points) Initial guess -1 3. (2 points) Initial guess A4.(2...
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 =...
Need help with number 3, thanks! 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...
*MATLAB CODE* 3)Write a function 'mydsort' that sorts a vector in descending order (using a loop, not the built-in sort function). 4)write a function that will receive a vector and will return two index vectors: one for ascending order and one for descending order. Check the function by writing a script that will call the function and then use the index vectors to print the original vector in ascending and descending order. **Please make sure they work. I have found...
3. Produce the function quadratic(a,b,c) where a, b, and c are the coeffi- cients of the quadratic ax2 + bx +c. The function should return: 1. a list of the two roots of ax2 + bx +c= 0, when two roots exist 2. the first root is the smaller of the two 3. if ax2 + bx +c=0 has no real roots, then return None. 4. if the quadratic has one real root only, then return a list with a...
MATLAB Code: ?MATLAB Code: Write a function that converts a given letter grade it will print its equivalence in numerical scale. For example if the user enters A, then your function should print a message stating that the grade must be between 90 and 100. B is between 80 and 89, etc. Everything under 60 is F. Use the switch-case function. Use fprintf to display the results on the screen.
a) Obtain a rough estimate of all real roots of the function f)ex x-2 by incremental searching in [-2,2]. Use Ax1 b) Ob tain two iterating functions for finding each of these roots by fixed-point iteration by solving for each χ which appears in the equation. Without doing any iterations, determine if each iterating function will converge to each root and state whether the convergence or divergence will be monotonic or oscillatory d) c) From the iterating functions obtained in...