Question

In: Electrical Engineering

EENG 1910: Project I – Introduction to Electrical Engineering Assignment-8 1. Create a MATLAB function that...

EENG 1910: Project I – Introduction to Electrical Engineering Assignment-8

1. Create a MATLAB function that will take as inputs the radius

(r) and height (h) of a cone and calculate its volume. The formula to compute the volume of a cone is as follows.

1

? = 3 ??2ℎ

Write a descriptive comment on the use of the function so that

the user by typing help nameofyourfunction has all the necessary information to use your function.

In each of the following questions (2. & 3.), first, evaluate the given MATLAB code for each of the test cases without using MATLAB. Then, using MATLAB, check the answers you obtained first.

2.

if n >

1

a. n

=

-25

m

=

?

m =

n+1

b. n

=

2

m

=

?

elseif

n==0

c. n

=

10

m

=

?

m =

n

d. n

=

0

m

=

?

else

m =

n-10

end

3.

switch letter                a. letter = ‘p’ case ‘x’       b. letter = ‘y’ disp(‘Hello’)         c. letter = ‘q’ case{‘y’, ‘Y’}          d. letter = ‘Q’

disp(‘Yes’)           e. letter = ‘x’ case ‘Q’

disp(‘Quit’)

otherwise

disp(‘Error’)

end

Note: When you copy and paste codes into MATLAB, some characters may not correctly translate. As a result, you may have to correct them for the script to run properly.

  1. A switch statement can often be used in place of a nested if- else or an if statement with many elseif clauses. Switch statements are used when an expression is tested to see whether it is equal to one of several possible values.

The script pickPizzaCase.m posted on Canvas is written using a case statement. Analyze it and convert it to if-elseif-else statement.

  1. Write MATLAB script that will prompt the user for a temperature in degrees Celsius, and then a letter ‘F’ for Fahrenheit or ‘K’ for Kelvin. The script should work weather a capital or small case letter is entered. The script will then print the corresponding temperature in the scale specified by the user. For example, the outputs might look as follows.

>> conversioncode

Please enter a temperature value in Celsius: 45 Do you want K or F? k

The temperature in Kelvin is: 318.15.

Please enter a temperature value in Celsius: 29.3 Do you want K or F? f

The temperature in Fahrenheit is: 84.74.

>> conversioncode

Please enter a temperature value in Celsius: 78 Do you want K or F? K

The temperature in Kelvin is: 351.15.

>> conversioncode

Please enter a temperature value in Celsius: 74 Do you want K or F? P

Please enter F or K!

Note: Lesson-8 has a sample code that could simply be modified. Also, conversioncode is simply the name that I have given to my script. The conversions can be performed using the formulas below.

? = ? + 273.15

? = 9 ? + 32

5

  1. Use a for loop to sum the elements in the following vector: V=[10, 27, -66, 43, 72, 87, 56,98, 33, 23.5, 8.5, 77.7, 36, 24,11, 85, 55, 63, 4, 39, 100, -96, 4, 41, 189, -9,78.3, -83]. You will need to first determine the size (length) of the vector. Check your answer using the MATLAB sum function.
  1. Repeat the previous problem, this time using a while loop.
  1. Create a function called “isInt” to check whether an input number is an integer. The function should display a sentence of the form: “22.5 is not an integer!” or “99 is an integer!” if the inputs were respectively 22.5 and 99.
  1. In chemistry, the pH of an aqueous solution is a measure of its acidity. The pH scale ranges from 0 to 14, inclusive. A solution with a pH of 7 is said to be neutral, a solution with a pH greater than 7 is basic, and a solution with a pH less than 7 is acidic. Write a script that will prompt the user for the pH of a solution, and will print whether it is neutral, basic, or acidic. If the user enters an invalid pH, an error message should be printed.

Solutions

Expert Solution

Question 1

function [V] = Volume_Cone(r,h)
% This function Volume_Cone(r,h) calculates the volume of a cone
% 'h' is the height of the cone
% 'r' is the radius of the cone
% 'V is the volume of the cone

V = 3*pi*r*h;
end

Question 2

The given segment is

if n>1
m = n+1
elseif n == 0
m = n
else
m = n - 10
end

First Case : n = -25

Since n is not greater than 1 and n is not equal to 0, the command m = n - 10 will be executed and the value of m will be m = -25 - 10 = -35

Checking using MATLAB

clc;

n = -25;
if n>1
m = n+1
elseif n == 0
m = n
else
m = n - 10
end

After execution command window is


m =

-35

>>

Second Case : n = 2

Since n >1 , the command , m = n+1 will be executed and the value of m will be m = n+1 = 3

Checking using MATLAB

clc;

n = 2;
if n>1
m = n+1
elseif n == 0
m = n
else
m = n - 10
end

After execution command window is


m =

3

>>

Third Case : n = 10

Since n >1 , the command , m = n+1 will be executed and the value of m will be m = 10+1 = 11

Checking using MATLAB

clc;

n = 10;
if n>1
m = n+1
elseif n == 0
m = n
else
m = n - 10
end

After execution command window is


m =

1

>>

Fourth Case : n = 0

Since n is not greater than 1, the next else will be checked, ie if n == 0. Since n = 0, the command , m = n will be executed and the value of m will be m = n= 0

Checking using MATLAB

clc;

n = 0;
if n>1
m = n+1
elseif n == 0
m = n
else
m = n - 10
end

After execution command window is


m =

0

>>

Question 3

clc;
letter = 'p';

switch letter
case 'x'
disp('Hello');
case {'y','Y'}
disp('Yes');
case 'Q'
disp('Quit');
otherwise
disp('Error')
end

First : letter = 'p'

Since the letter is not in any of the cases of switch, the command window will have Error displayed

Checking using MATLAB

clc;
letter = 'p';

switch letter
case 'x'
disp('Hello');
case {'y','Y'}
disp('Yes');
case 'Q'
disp('Quit');
otherwise
disp('Error')
end

After execution command window is

Error
>>

Second : letter = 'y'

Since the letter is in one of the case statement, the command window will have Yes displayed

Checking using MATLAB

clc;
letter = 'y';

switch letter
case 'x'
disp('Hello');
case {'y','Y'}
disp('Yes');
case 'Q'
disp('Quit');
otherwise
disp('Error')
end

After execution command window is

Yes
>>

Third : letter = 'q'

Since the letter is not in any of the cases of switch, the command window will have Error displayed

Checking using MATLAB

clc;
letter = 'q';

switch letter
case 'x'
disp('Hello');
case {'y','Y'}
disp('Yes');
case 'Q'
disp('Quit');
otherwise
disp('Error')
end

After execution command window is

Error
>>

Fourth: letter = 'Q'

Since the letter is in one of the case statement, the command window will have Quit displayed

Checking using MATLAB

clc;
letter = 'Q';

switch letter
case 'x'
disp('Hello');
case {'y','Y'}
disp('Yes');
case 'Q'
disp('Quit');
otherwise
disp('Error')
end

After execution command window is

Quit
>>

Fifth: letter = 'x'

Since the letter is in one of the case statement, the command window will have Hello displayed

Checking using MATLAB

clc;
letter = 'x';

switch letter
case 'x'
disp('Hello');
case {'y','Y'}
disp('Yes');
case 'Q'
disp('Quit');
otherwise
disp('Error')
end

After execution command window is

Hello
>>

Question 4

function [Temp] = ConversionCode()
%This function converts the temperature in degree Celcius to degree
%Farenheit of Kelvin according to the user's choice

C = input('Please enter a temperature value in Celsius:');

choice = input(' Do you want K or F?');

switch choice
case {'k','K'}
K = C + 273.15;
disp('The temperature in Kelvin is:');
disp(K);   
  
case {'f','F'}
F = 9*C + 32;
disp('The temperature in Fahrenheit is:');
disp(F);
otherwise
disp('Please enter F or K!');
end
  

end

Question 5

clc;

V=[10, 27, -66, 43, 72, 87, 56,98, 33, 23.5, 8.5, 77.7, 36, 24,11, 85, 55, 63, 4, 39, 100, -96, 4, 41, 189, -9,78.3, -83];
N = length(V);

S = 0;
for i=1:N
S = S + V(i);
end

disp('The Sum f the numbers is:')
disp(S);

disp('The Sum of the numbers using the function sum is:')
sum(V)

Question 6

clc;

V=[10, 27, -66, 43, 72, 87, 56,98, 33, 23.5, 8.5, 77.7, 36, 24,11, 85, 55, 63, 4, 39, 100, -96, 4, 41, 189, -9,78.3, -83];
N = length(V);

S = 0;
i = 1
while i<= N
S = S + V(i);
i = i + 1;
end

disp('The Sum f the numbers is:')
disp(S);

disp('The Sum of the numbers using the function sum is:')
sum(V)

Question 7

function [] = isInt(n)
%This function checks whether the number is an integer or not

if floor(n)==n
fprintf('"%d is an integer"\n', n);
else
fprintf('"%d is not an integer"\n',n);
end

Question 08

clc

pH = input('Enter the pH of the solution');

if pH <7 & pH >=0
disp('The solution is acidic');
elseif pH==7
disp('The solution is neutral');
elseif pH>7 & pH<=14
disp('The solution is basic');
else
disp('Error!!!. pH will be between 0 and 14');
end


Related Solutions

I am in this electrical engineering project course in which an assignment is asking me this...
I am in this electrical engineering project course in which an assignment is asking me this and I cannot make heads or tails of what it means by this... Discuss the tradeoffs involved between using patents and trade secrets to protect intellectual property. Please be as descriptive as possible, THANKS
MATLAB Assignment 8 Introduction to Linear Algebra (Weeks 11 and 12) Spring, 2018 1. MATLAB Submission...
MATLAB Assignment 8 Introduction to Linear Algebra (Weeks 11 and 12) Spring, 2018 1. MATLAB Submission Problem 3 ( Due Date : May 24 (Thu) ) Referring to the instruction below, you are required to submit this problem. A common problem in experimental work is to find a curve y = f(x) of a specified form corresponding to experimentally determined values of x and y, say (x1, y1), (x2, y2), · · · , (xn, yn). The followings are the...
Matlab assignment. The objectives of this project are (1) to introduce the students to scripting applied...
Matlab assignment. The objectives of this project are (1) to introduce the students to scripting applied to solution of mechanical engineering problems and (2) to create a Matlab script that allows the computation of principal stresses and strains starting from a generic state of stress and that automates the drawing of 3D Mohr circles Assignment 1) Read from input a stress tensor (3D); 2) For any state of 3D stress compute the principal stress values (σ1, σ2, σ3) with σ1...
IN MATLAB, Create a 8x8 magic matrix. Then use MATLAB built in function, sum, to calculate...
IN MATLAB, Create a 8x8 magic matrix. Then use MATLAB built in function, sum, to calculate the sum of each column. Use subscript notation to find the 6th element and the last element of each magic square. Find the maximum of all the elements in each magic square.
Exercise 3 Part 1. Solving a system Ax = b **Create a function in MATLAB that...
Exercise 3 Part 1. Solving a system Ax = b **Create a function in MATLAB that begins with: function [C,N]=solvesys(A) [~,n]=size(A); b=fix(10*rand(n,1)) format long We are using format long to display a number in exponent format with 15 digit mantissas. If later on, you will need to switch back to the default format, type and run format The input is an matrix A. If A is invertible, the outputs are the matrix C, whose 3 columns x1, x2, x3 are...
There is an engineering project that uses complex numbers, electrical circuits. you need to develop a...
There is an engineering project that uses complex numbers, electrical circuits. you need to develop a user-defined structure type and a set of operations that will make complex arithmetic virtually as straightforward as arithmetic on C’s built-in numeric types. You will need to define functions for complex I/O as well as for the basic arithmetic operations (addition, subtraction, and for finding the absolute value of a complex number). Hint: the complex number a + bi has a real part a...
Database Application Development Project/Assignment Milestone 1 (part 1) Objective: In this assignment, you create a simple...
Database Application Development Project/Assignment Milestone 1 (part 1) Objective: In this assignment, you create a simple HR application using the C++ programming language and Oracle server. This assignment helps students learn a basic understanding of application development using C++ programming and an Oracle database Submission: This Milestone is a new project that simply uses what was learned in the SETUP. Your submission will be a single text-based .cpp file including your C++ program for the Database Application project/assignment. The file...
I am currently completing an assignment for an introduction for accounting. I have been asked to...
I am currently completing an assignment for an introduction for accounting. I have been asked to complete a general journal for the following transactions: August 2           Sahra paid $30 from the business bank account for dinner at ‘Waves’ a beachside café. August 3           Deep Sea Cleaning Co cleaned the shop and workshop and left an invoice for $195 on the counter. August 6           A new range of SPF fabric was purchased from ‘World Fabrics Ltd’ for $6,200. A part-payment of $200 was paid...
    2. Case Background Introduction:     The project company is ValueVehicle (VV), which is a hypothetical electrical vehicle...
    2. Case Background Introduction:     The project company is ValueVehicle (VV), which is a hypothetical electrical vehicle manufacturer. VV is a public listed company and is required to comply with all regulations from SEC and GAAP. Your group is the accounting department, and you are responsible for disclosing financial information to the SEC and the public.     (1) Company necessary financial information VV (formerly ValueVehicle, Inc.) is an American electric vehicle and clean energy company based in Fayetteville, North Carolina. VV's current...
I need some ideas for software engineering project
I need some ideas for software engineering project
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT