Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

( a ) Sketch a flowchart ( Visio diagram ) for Matlab code that repeatedly prompts a user to enter ( 5 marks ) a

(a) Sketch a flowchart (Visio diagram) for Matlab code that repeatedly prompts a user to enter
(5 marks)
a prime number until the user enters a prime number. Use a while loop and an if statement.
(b) Write a Matlab code snippet for the problem outlined in (a) above. Your code should output appropriate messages when the number entered is, and is not, a prime number. Hint: Use a while loop and Matlab's input (), disp ()/ fprintf () and
(5 marks)
isprime () functions.
(c) Consider the arrays below containing the names of elements and their corresponding atomic weights:
element=["Hydrogen" "Helium" "Lithium"];
a_weight =[1.007,4.003,6.941];
Using Matlab's fprintf() function, write code that uses a for loop to print out the following:
The atomic weight of Hydrogen is 1.007amu
The atomic weight of Helium is 4.003amu
The atomic weight of Lithium is 6.941amu
(5 marks)
(d) Write a piece of code that uses a nested for loop and an if statement to display the array elements whose value is less than 5.
E=[2371391083]
marks)
(e) Write down the command to delete row 2 from the matrix F below:
F=[123654978]
(5 marks)
(f) Write a piece of code to plot pressure, P, against temperature, T and volume, V, against temperature, T, on the same graph.
(5 marks)
(g) Write a user defined function in MATLAB that takes two square matrices of equal size and multiplies them elementwise. Show:
The code for the user defined function
How to call the user defined function from another script (.m filc)
(5 marks)
Use matlab please.
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions