Question

MATLAB HELP : Create a MATLAB function starting as follows:- Function [root1,root1] = quadraticroots (a,b,c) to...

MATLAB HELP :

Create a MATLAB function starting as follows:-

Function [root1,root1] = quadraticroots (a,b,c) to find the roots of a quadratic function. To test your function find the roots of the following equation:-

X^2+5x+6=0

Submit the complete listing and results of a run with the variable a=1,b=5 and c=6.

Your file should contain at least the following:-

Purpose of the function,

Description of the input and output variables,

Call statement(s),

PLEASE SHOW FULL SCRIPT OF THE MATLAB with results .

0 0
Add a comment Improve this question Transcribed image text
Answer #1

The MTALAB Function file (quadraticroots.m) below

function [root1,root2] = quadraticroots (a,b,c)
% thif function computes the roots of the the
% quadratic equation from given value of a,b,c

%input parameters are a,b,c

%output : root1,root2 : represents two roots
d=b*b-4*a*c; % find discriminant
if(d>=0)
root1=(-b+sqrt(d))/(2*a); %compute root1
root2=(-b-sqrt(d))/(2*a); %compute root2
end
end

The MATLAB Script File below

% this script is given for test purpose to call the quadraticroots() function
% to slove aquadratic equation.
clc;
a=1;
b=5;
c=6;
%call quadraticroots (a,b,c) function
[root1,root2]=quadraticroots (a,b,c);
%print the roots
fprintf('\nRoot1= %f',root1);
fprintf('\nRoot2= %f',root2);
fprintf('\n');

//The sample run with a=1. b=5, c=6;

Add a comment
Know the answer?
Add Answer to:
MATLAB HELP : Create a MATLAB function starting as follows:- Function [root1,root1] = quadraticroots (a,b,c) to...
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
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
ADVERTISEMENT