MatLab Question In fluid dynamics the Reynolds number Re is

MatLab Question

In fluid dynamics, the Reynolds number Re is a dimensionless number used to determine the nature of a fluid flow. For an internal flow (e.g., water flow through a pipe), the flow can be categorized as follows: Write a script that will prompt the user for the Reynolds number of a flow and will print the region the flow is in. Then, answer the following question. Would it be a good idea to write the selection statements using switch? (Why or why not?)

Solution

main.m

clc;
close all;
clear all;
Re = input(\'enter rynolds number of flow : \')

if Re<=2300
disp(\'The flow is in Leminar Region\')
elseif Re>2300 && Re<=4000
    disp(\'The flow is in Transition Region\')
else
disp(\'The flow is in Turbulent Region\')
end

Output :

enter rynolds number of flow : 2000

Re = 2000

The flow is in Leminar Region

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

Yes, It would be good idea to write selection statements using switch because unlike if-then and if-then-else statements, the switch statement can have a number of possible execution paths. A switch works with a scalar, a string, or a cell array of scalars or strings

A switch block conditionally executes one set of statements from several choices. Each choice is a case.

An evaluated switch_expression is a scalar or string. An evaluated case_expression is a scalar, a string, or a cell array of scalars or strings. The switch block tests each case until one of the cases is true. A case is true when:

For numbers, isequal(case_expression,switch_expression).

For strings, strcmp(case_expression,switch_expression).

For cell array case expressions, switch_expression is a member of the case_expression.

When a case is true, MATLAB executes the corresponding statements, and then exits the switch block.

otherwise is optional, and executes only when no case is true.

MatLab Question In fluid dynamics, the Reynolds number Re is a dimensionless number used to determine the nature of a fluid flow. For an internal flow (e.g., wa

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site