Sunday, June 13, 2021

Write a MATLAB Program by using (anonymous function) command to calculate the volume of (Cube and Cylinder).

1. Write a MATLAB Program by using (anonymous function) command to calculate the volume of (Cube and Cylinder). 

2. Write a MATLAB Program by using (anonymous function) command to calculate the following equation. Sine(x)=(e?x-p-2)/6

Solution 

Part 1 Solution

volCube = @(a) (a*a*a);

promptl = "Enter side of cube: ";

side = input(promptl); 

volume1 = volCube(side);

fprintf("The volume of the cube is %d",volumel) 

volCylinder = @(r,h) (pi*r*r*h); 

prompt2 = "\ n\nEnter radius of cylinder: ";

radius = input(prompt2);

prompt2 = "Enter height of cylinder: ";

height = input(prompt2);

volume2 = volCylinder(radius,height);

fprintf("The volume of the cylinder is %f",volume2) 


Part 2 Solution

sin = @(o) ((exp(2.x)-exp(-2*x))/6);

prompt2 = "\n\nEnter value of x: ";

x = input(prompt2);

valSinx = sin(x);

fprintf("The value of sinx is %f",valSinx)


Output:- 

1. Write a MATLAB Program by using (anonymous function) command to calculate the volume of (Cube and Cylinder).   2. Write a MATLAB Program by using (anonymous function) command to calculate the following equation. Sine(x)=(e?x-p-2)/6



No comments:

Post a Comment