Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Use MATLAB in all problems and be sure to use suitable MATLAB variable names. 18

ID: 3704143 • Letter: U

Question

Use MATLAB in all problems and be sure to use suitable MATLAB variable names. 18.1 (User-Defined Functions) Write a user-defined function that does the following depending on the number of inputs: 6 inputs variables6 input 4 double variables Distance of line between 2 Points Circle formed by 3message: incorrect variables Calculate Radius of Provide error oints number of inputs The Radius of a circle given 3 points in space is: Radius- where Ln= length of each side of the triangle L1 * L2 * L;3 tri Atri- area of triangle formed by 3 points. Example of 3 points input and resulting radius: Point Point 1 2.9987396 0.5287587 Point 2 2.9412441 0.7881040 Point 3 2.8613640 1.0414513 radius xl,yl: x2,y2: x3,y3 Radius 3.045

Explanation / Answer

ScreenShot

------------------------------------------------------------------------------------------------------------------------------------------

Program

%variable initialization
x1=0.0;
y1=0.0;
x2=0.0;
y2=0.0;
x3=0.0;
y3=0.0;
%circle radius calculation function
function radius=circleRadius(x1,y1,x2,y2,x3,y3)
   L1=double(sqrt(((x2-x1)^2)+((y2-y1)^2)));
   L2=double(sqrt(((x3-x2)^2)+((y3-y2)^2)));
   L3=double(sqrt(((x3-x1)^2)+((y3-y1)^2)));
   Atri=double((1/2)*((x1*(y2-y3))-(x2*(y1-y3))+(x3*(y1-y2))));
   radius=(L1*L2*L3)/(4*Atri);
end
%Line distance calculation function
function distance=lineDistance(x1,y1,x2,y2)
   distance=double(sqrt(((x2-x1)^2)+((y2-y1)^2)));
end
%Prompt the user input
inputValues=input('Enter points values:');
%find the count of input
n=numel(inputValues);
%less than 4 or greater than 6 error message
if n<4 | n>6
   fprintf('In correct number of inputs!!')
   %distance function call and print
elseif n==4
   distnace=lineDistance(inputValues(1),inputValues(2),inputValues(3),inputValues(4));
   fprintf('Point          X          Y ')
   fprintf('======        ====       ==== ')
   fprintf('Point1        %1.7f       %1.7f ',inputValues(1),inputValues(2))
   fprintf('Point2        %1.7f       %1.7f ',inputValues(3),inputValues(4))
   fprintf("Radius=%1.3f ",distnace)
   %circle radius function call and print

else
   radius=lineDistance(inputValues(1),inputValues(2),inputValues(3),inputValues(4),inputValues(5),inputValues(6));
   fprintf('Point          X          Y ')
   fprintf('======        ====       ==== ')
   fprintf('Point1        %1.7f       %1.7f ',inputValues(1),inputValues(2))
   fprintf('Point2        %1.7f       %1.7f ',inputValues(3),inputValues(4))
   fprintf('Point3        %1.7f       %1.7f ',inputValues(5),inputValues(6))
   fprintf("Radius=%1.3f ",radius)
end

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote