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

Using MATLAB and given the known values and the equation below 2. Calculate an a

ID: 3856309 • Letter: U

Question

Using MATLAB and given the known values and the equation below

2. Calculate an array of temperature values one at a time using a loop. You may not use vectorized techniques to accomplish this.

4. Experiment with the time step size, allowing the time step to become larger and smaller. Calculate the wall time (i.e. the "real time") for runs of both the vectorized and loop-based approaches as you vary the time step size.

Is one approach faster than the other? Does it depend on how big the data set is? Leave code for at least three numerical experiments in the project file you submit for a grade.

Print your responses to these questions to a data file located on the desktop of the machine you are using; be sure to close that file when you are done.

In this case

Ta = 68 F

To = 180 F

K = 0.0719

Cup of coffee is made at 12:00 pm noon.

Explanation / Answer

MATLAB® is optimized for operations involving matrices and vectors. The process of revising loop-based, scalar-oriented code to use MATLAB matrix and vector operations is called vectorization. Vectorizing your code is worthwhile for several reasons:

Appearance: Vectorized mathematical code appears more like the mathematical expressions found in textbooks, making the code easier to understand.

Less Error Prone: Without loops, vectorized code is often shorter. Fewer lines of code mean fewer opportunities to introduce programming errors.

Performance: Vectorized code often runs much faster than the corresponding code containing loops.

Vectorizing Code for General Computing

This code computes the sine of 1,001 values ranging from 0 to 10:

This is a vectorized version of the same code:

The second code sample usually executes faster than the first and is a more efficient use of MATLAB. Test execution speed on your system by creating scripts that contain the code shown, and then use the tic and toc functions to measure their execution time.

Vectorizing Code for Specific Tasks

This code computes the cumulative sum of a vector at every fifth element:

Using vectorization, you can write a much more concise MATLAB process. This code shows one way to accomplish the task:

Array Operations

Array operators perform the same operation for all elements in the data set. These types of operations are useful for repetitive calculations. For example, suppose you collect the volume (V) of various cones by recording their diameter (D) and height (H). If you collect the information for just one cone, you can calculate the volume for that single cone:

Now, collect information on 10,000 cones. The vectors D and H each contain 10,000 elements, and you want to calculate 10,000 volumes. In most programming languages, you need to set up a loop similar to this MATLAB code:

With MATLAB, you can perform the calculation for each element of a vector with similar syntax as the scalar case:

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