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

Background MATLAB has many built-in functions, but unfortunately there are many

ID: 3744033 • Letter: B

Question

Background MATLAB has many built-in functions, but unfortunately there are many functions in the real world. Your task is to write custom functions that may come in handy later. If you store these functions in a folder that you've saved to your path list ("Set Path" from toolbar, then add the folder), then you can call them in any program you write Problem Part 1 For each of the following 3D shapes, write a function that takes however many inputs are necessary and returns two outputs: volume and surface area. Be sure to explain the inputs and outputs in the comment headings! Shape Cube Rectangular prism Cylinder Cone Sphere General ellipsoid Function name CubeVolSA RecPrismVolSA CylVolSA ConeVolSA SphereVolSA EllVolSA Number inputs 1 input 3 inputs 2 inputs 2 inputs 1 input 3 inputs S2 (a bac bc)1/ where p 1.6075) Part 2 Create an .m file (not a custom function) called PA1part2 with the sections shown. NO numbers should appear after the Declarations section! %% Declarations (each variable on its own line) % Anonymous functions (again, each function on its own line) OblSphVolFracUnc; %% Calculations (three volumes, three uncertainties, six lines) %% Output (display the results using fprintf) Do NOT use the input function for any variables. The user will manually define the variables' values. Define two anonymous functions: one for the fractional uncertainty of a two-variable equation and one for the volume of an oblate spheroid 4 "Calculations" should calculate the volume given R and H and the associated uncertainty. You should use your functions from Part 1 for the cone and cylinder. The "Output" section should present your results using fprintf for all three shapes with t and 3 symbols and THREE values after the decimal. Assume that the units are in centimeters in your output and when you comment your variables

Explanation / Answer

Matlab function files:--

Part1:--

CubeVolSA.m filr:--

function [vol, sa]=CubeVolSA(side)

    vol=side^3;

    sa=6*side^2;

end

RecPrismVolSA.m file:--

function [vol, sa]=RecPrismVolSA(length,berth,height)

    vol=length*height*berth;

    sa=2*(length*berth+berth*height+height*length);

end

CylVolSA.m file:--

function [vol, sa]=CylVolSA(radius, height)

    vol=pi*radius^2*height;

    sa=2*pi*radius*height+2*pi*radius^2;

end

ConeVolSA.m file:--

function [vol, sa]=ConeVolSA(radius,height)

    vol=pi*radius^2*height/3;

    sa=pi*radius*(radius+sqrt(height^2+radius^2));

end

SphereVolSA.m file:--

function [vol, sa]=SphereVolSA(radius)

    vol=4/3*pi*radius^3;

    sa=4*pi*radius^2;

end

EllVolSA.m file:--

function [vol, sa]=EllVolSA(a,b,c)

    p=1.6075;

    vol=4/3*pi*a*b*c;

    sa=2*pi*(a^p*b^p+a^p*c^p+b^p*c^p)^1/p;

end

part2:--

OblSphVol.m file:--

function [vol]=OblSphVol(radius,height)

    vol=4/3*pi*radius^2*height;

end

FracUnc.m file:--

function [df1,df2]=FracUnc(vol,dvol,vol1,vol2)

    df1=abs((vol-dvol)-vol1);

    df2=abs((vol+dvol)-vol2);

end

Pa1part2.m file:-- (this is main file)

clear;

clc;

%declarations

R=10;

dR=0.1;

H=5;

dH=0.1;

%anonymous function with calculations see OblSphVol.m

vol=OblSphVol(R,H);

dvol=OblSphVol(dR,dH);

vol1=OblSphVol(R-dR,H-dH);

vol2=OblSphVol(R+dR,H+dH);

Conevol=ConeVolSA(R,H);

Conedvol=ConeVolSA(dR,dH);

Conevol1=ConeVolSA(R-dR,H-dH);

Conevol2=ConeVolSA(R+dR,H+dH);

Cylvol=CylVolSA(R,H);

Cyldvol=CylVolSA(dR,dH);

Cylvol1=CylVolSA(R-dR,H-dH);

Cylvol2=CylVolSA(R+dR,H+dH);

[df1,df2]=FracUnc(vol,dvol,vol1,vol2); %see FracUnc.m

[Cyldf1,Cyldf2]=FracUnc(Cylvol,Cyldvol,Cylvol1,Cylvol2);

[Conedf1,Conedf2]=FracUnc(Conevol,Conedvol,Conevol1,Conevol2);

%output

fprintf('Uncertainity in Volume of oblate spheroid is -%.3f and +%.3f ',df1,df2);

fprintf('Uncertainity in Volume of oblate spheroid is -%.3f and +%.3f ',Cyldf1,Cyldf2);

fprintf('Uncertainity in Volume of oblate spheroid is -%.3f and +%.3f ',Conedf1,Conedf2);

output:--

Uncertainity in Volume of oblate spheroid is -82.729 and +84.823

Uncertainity in Volume of oblate spheroid is -62.046 and +63.617

Uncertainity in Volume of oblate spheroid is -20.682 and +21.206

>>

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