Change the current directory to mynewdir. Then open an Edit Window and add the following lines: 8\. Create an input array from \(-2\) *pi to 2 *pi \(t=-2 * \mathrm{pi}: \mathrm{p} i / 10: 2^{\circ} \mathrm{pi}\); of Calculate |sin(t)| \(x=a b s(\sin (t))\); \- Plot result plot \((t, x)=\) Save the file with the name test2. \(m\), and execute it by typing test 2 in the Command Window. What happens?

Short Answer

Expert verified
To solve this exercise, follow these steps: 1. Change the working directory to 'mynewdir' using `cd mynewdir`. 2. Create an input array from -2π to 2π with a step of π/10: `t = -2 * pi : pi / 10 : 2 * pi;`. 3. Calculate the absolute value of the sine function for each element: `x = abs(sin(t));`. 4. Plot the sine function: `plot(t, x)`. 5. Save the code in a file named 'test2.m'. 6. Execute the file 'test2.m' by typing `test2`. The plot shows the sine function with the input array as the x-axis and the absolute value of the sine function as the y-axis.

Step by step solution

01

Change Current Directory

Change the current working directory to 'mynewdir' by typing the following command in the command window: ``` cd mynewdir ```
02

Create Input Array

To create an input array from -2π to 2π with a step of π/10, type the following line into the Edit Window: ``` t = -2 * pi : pi / 10 : 2 * pi; ```
03

Calculate Sine Function

To calculate the absolute value of the sine function for each element in the input array, type: ``` x = abs(sin(t)); ```
04

Plot the Sine Function

To plot the sine function, type the following line in the Edit Window: ``` plot(t, x) ```
05

Save the Code

Save the code in a file named 'test2.m' by clicking File > Save As, and then typing test2.m in the filename textbox.
06

Execute the File

To execute the file 'test2.m', type the following command in the Command Window: ``` test2 ``` Now you will see a plot of the sine function displayed with the input array as the x-axis and the absolute value of the sine function as the y-axis.

Unlock Step-by-Step Solutions & Ace Your Exams!

  • Full Textbook Solutions

    Get detailed explanations and key concepts

  • Unlimited Al creation

    Al flashcards, explanations, exams and more...

  • Ads-free access

    To over 500 millions flashcards

  • Money-back guarantee

    We refund you if you fail your exam.

Over 30 million students worldwide already upgrade their learning with Vaia!

One App. One Place for Learning.

All the tools & learning materials you need for study success - in one app.

Get started for free

Most popular questions from this chapter

Get help on the MATLAB function exp using: (a) The "help exp" command typed in the Command Window, and \((b)\) the Help Browser.

Assume that \(a, b, c\), and \(d\) are defined as follows, and calculate the results of the following operations if they are legal. If an operation is illegal, explain why it is illegal. $$ \begin{array}{ll} a=\left[\begin{array}{rr} 2 & -2 \\ -1 & 2 \end{array}\right] & b=\left[\begin{array}{rr} 1 & -1 \\ 0 & 2 \end{array}\right] \\ c=\left[\begin{array}{r} 1 \\ -2 \end{array}\right] & d=\text { eye }(2) \end{array} $$ a. result \(=a+b\); b. result \(=a=d_{i}\) c. result \(=a\). * \(d\); d. result \(=a \cdot c\); c. reault \(=a . * c\) ? f. result \(=a \backslash b\) : g. result \(=a .1 \mathrm{~b}\) : h. result \(=a . A b\);

The following MATLAB statements plot the function \(y(x)=2 e^{-02 x}\) for the range \(0 \leq x \leq 10\). \(x=0: 0.1: 10 ;\) \(y=2 * \exp (-0.2 \cdot x) ;\) \(p 10 t(x, y):\) Use the MATLAB Edit Window to create a new empty M-file, type these statements into the file, and save the file with the name teat. 1 .m. Then, execute the program by typing the name test 1 in the Command Window. What result do you get?

Suppose that \(u=1\) and \(v=3\). Evaluate the following expressions asing MATLAB. a. \(\frac{4 u}{3 v}\) b. \(\frac{2 v^{-2}}{(u+v)^{2}}\) c. \(\frac{v^{3}}{v^{3}-u^{3}}\) d. \(\frac{4}{3} \pi v^{2}\)

Close the Figure Window, and change back to the original directory that MATLAB started in. Next type "test2" in the Command Window. What happens, and why?

See all solutions

Recommended explanations on Psychology Textbooks

View all explanations

What do you think about this solution?

We value your feedback to improve our textbook solutions.

Study anywhere. Anytime. Across all devices.

Sign-up for free