Page 1 of 1

1. Basic MATLAB computations: Set up variables 2 = 6 and y = 5, then compute ry, x² + y² and x/(3y). 2. Displaying infor

Posted: Mon Jun 06, 2022 6:04 pm
by answerhappygod
1 Basic Matlab Computations Set Up Variables 2 6 And Y 5 Then Compute Ry X Y And X 3y 2 Displaying Infor 1
1 Basic Matlab Computations Set Up Variables 2 6 And Y 5 Then Compute Ry X Y And X 3y 2 Displaying Infor 1 (42.88 KiB) Viewed 26 times
1 Basic Matlab Computations Set Up Variables 2 6 And Y 5 Then Compute Ry X Y And X 3y 2 Displaying Infor 2
1 Basic Matlab Computations Set Up Variables 2 6 And Y 5 Then Compute Ry X Y And X 3y 2 Displaying Infor 2 (100.17 KiB) Viewed 26 times
1. Basic MATLAB computations: Set up variables 2 = 6 and y = 5, then compute ry, x² + y² and x/(3y). 2. Displaying information: In addition to removing the semicolons used to suppress output, the disp command can be used to show information, along with text, on the screen. Look up the command. The easiest way to work this out is to use the disp command, and if you combine strings in brackets, MATLAB will automatically concatenate them. Put the line disp(['The number x is num2str(x) '.']); and see what the result is. Do the same for the number y and the product ry. 3. If statements: The code in the file generates a random integer between 1 and 100. Write an if statement to determine if this number is even. If it is even use disp to say so ("The number 4 is even."), and if not, say that the number is odd. Hint: The function mod is the key to writing this if statement. Having remainder 0 when divided by 2 means that a number is even.

4. For loops: The Fibonacci numbers are a common concept in mathematics, and they are easily generated using a for loop. Write a loop to generate the first 20 Fibonacci numbers and store them all in an array. After you are done, display the array. The Fibonacci numbers F, are defined by F₁ = 1 F₂ = 1 Fn = Fn-1 + Fn-2 so that at each step, you need to add up the previous two numbers to get the next one. This recursion lends itself very well to a for loop. To complete this problem, you should display all Fibonacci numbers from 1 to 20 using the numbering started above. This can be done with the disp command. 5. Graphs: Draw a graph of the functions f(x) = sin(x) and g(x)= x-1 over the range [0,3]. Draw f(x) in blue and g(x) in red. First, draw the graphs on two separate figures, then draw them both on the same figure. To make sure that figures separate, you can use the figure(); command. In addition, hold on and hold off will make it so consecutive plots show up on the same axes. The easiest way to do this is with anonymous functions after defining a range of a values by something like xVals = linspace(0, 3, 1000). Note: You should not use the fplot function for this, but use the plot function instead. I know the first is a simple way to draw graphs, but the rest of the code for this semester will run on anonymous functions. It's better to get used to them as soon as possible. For more information on anonymous functions, see the MATLAB documentation https://www. mathworks.com/help/matlab/matlab_prog/anonymous-functions.html. 6. Consider the differential equation dy dt =t-y²2 Use quiver244.m to draw a quiver plot of this differential equation on 0 ≤ t ≤ 5 and -3 ≤ y ≤ 10. What does it look like the solution will do if we start with y(0) = 3? What about for y(0) = 0 or y(0) = 8? Provide a description of what will happen to the solution. Note: For putting this together, remember that the anonymous function needs to be written as @(t,y), and the order of the variables is important. 7. Use samplePlots244.m to verify your results from the first part. Run the code with these different initial conditions and see what happens over time.