CPS118 - Second Half

अब Quizwiz के साथ अपने होमवर्क और परीक्षाओं को एस करें!

What is the rule for x0 when using the fzero function?

If it is a scalar, x0 must be a scalar value that is close to the X-AXIS if x0 is a vector it must be two points that are on opposite sides of the X-axis; implying they have opposite signs

What do you do if a function has more than one solution?

If using fzero, you should apply the function multiple times for each different x0. If it the function is a polynomial you can use the roots function though.

How do you add and subtract polynomials?

In order to add and subtract polynomial they must be the same length of vector, in order to make a vector the same length as another you must add 0s infront of the length of a vector if it isn't long enough.

How would you calculate the root of a polynomial function.

In order to calculate the root of a polynomial you can use the function r = roots(p) r is a column vector that is assigned with the roots of the polynomial, p is a row vector that contains the coefficients of the polynomial in matlab formation so [ 2 2 3 3 3] for example.

What is considered a root in Matlab?

It is only considered a root of a polynomial if the function crosses the x-axis, as opposed to just touching the x-axis like in mathematics.

How can you create a 3D plot such that it is spherical?

Just make a mesh or surface plot as usual, but first equate your X Y & Z to a function called sphere(n) n represents the number of faces that you want your 3D sphere to have. Then put what X Y Z represents now in the mesh or surface plot [X,Y,Z] = square(20); mesh(X,Y,Z)

What are the steps in order to make polar coordinates grid in the XY plane so you can make a polar 3D PLOT?

Make a grid of theta and r values using mesh grid compute z at each point convert grid with polar coordinates to grid with cartesian coordinates using the built in command 'pol2cart' Make the 3D plot using z and cartesian coordinates

What is a surface plot? How would you create one?

Surf plot is essentially the same as a mesh plot except that it is coloured in the tiles of the graph rather than just the outline coloured surf(x,y,z)

What must the first line of a function be in order to establish that it is indeed a function?

The first line must be the function line stating something like: function(output) = functionname(input) **NOTE The first line of a function can't be anything else but the function designation line otherwise MATLAB considers it to be a script file.

What function would allow you to compute the least-squares best fit of data points to a polynomial?

The p = polyfit(x,y,n) The p represents the vector of the coefficients of the polynomial which fits the data points. x represents a vector with the horizontal coordinate of the data points the independent variable y represents a vector with the vertical coordinate of the data points the dependent variable n represents the degree of the polynomial, remember if you want it passing through all the points you can use a degree of M-1 where M represents how many data points are present. A degree of n such that it is < m-1 can give you still an approximation of data. *essentially it just tries to provide a connect the dot look between a set of data points, so if you know data and want to plot the data without connecting them and then connect it after with a separate line then you can use this function

What are the H1 and help text lines for a function?

These are optional lines within your function, essentially what they do is provide some help on using your function. They are designated as help by putting it as comment within your function, so %Hey within your function when you use help(function) it will yield your comments all the lines of text with %

What is an anonymous function? How does it work?

This is a function that is essentially defined without using the whole create a new script file and save it under that name bigotry. This way you can define a simple short one-line function

How could you calculate the derivative of a polynomial?

To calculate the derivative of a polynomial, you can utilize the polymer function. k = polyder(p) p is a vector with the coefficients of the polynomial p k = polyder(a,b) a and b are vectors with the coefficients of the polynomials that are going to be multiplied together, essentially the product rule right? [n d] = polyder(u,v) Derivative of a quotient between two polynomials the U and V represent the numerator and denominator respectively n and d represent the numerator and denominator respectively

What are the 3 steps to make a mesh or surface plot?

To make a surface or mesh plot you would have to create a grid in the XY plane that contains the points you're interested in, use mesh grid(x,y) to do this easily Calculate Z with whatever way you want for each point of that grid Make the 3Dimensional Plot

How do variables within and outside functions work?

Variables inside and outside functions can have the same name or same whatever. The calling program doesn't acknowledge variables that are created within the function variables defined within the function are local to that function meaning that they are unknown to the main program, and variables in the main program are unknown to that function. *only through an argument can values from main program to a function

How would you determine the minimum of a function?

You could determine the minimum using the function [x y] = fminbnd(function,x1,x2) x1 and x2 is a range of values, so fminbnd(the function you want to find the min value of, between this number, and this number) In this way x1 will always be less than x2 X in the [x] will be the point where it occurs Y will be the minimum value of that function between that range The function will look for LOCAL minimum values. If no local minimum values are present than it will yield absolute minimums

How would you write a polynomial in MATLAB representation?

You have to set it up such that the numbers in the vectors are the coefficients of the polynomial

What trick would allow you to get your x and y independent variables in a form that is matrix like in order to use mesh and surface plots?

[X Y] =meshgrid(x,y) essentially x is a vector of a range of values that you want for your matrix. x = 1:5 Your matrix for X will be values 1 to 5 each row will be identical, the first and last number are the boundaries of the matrix y = 1:5 Your matrix for Y will be values 1 to 5 each column will be identical, the first and last number are the boundaries of the matrix X = 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 Y = 1 1 1 1 1 2 2 2 2 2 3 3 3 3 3 4 4 4 4 4 5 5 5 5 5 Now you can use your X and Y variables mathematically to determine a value of Z such that you can make your mesh or surface plot with these new values.

What way could you divide polynomials?

[q r] = deconv(u,v) q is the vector with the coefficients of the quotient polynomial. r is the vector with the coefficients of the remainder polynomial u is a vector that contains the coefficients of the polynomial in the numerator v is a vector that contains the coefficients of the polynomial in the denominator

Which function can allow you to multiply two polynomials?

c = conv(a,b) *it performs what is called a convolution a and b are two vectors such that the numbers correspond to the coefficients of polynomials.

Elaborate how you could solve for a function where it equals something other than 0.

determine what you want to solve for: f(x) = 10? then rearrange f(x) - 10 = 0 equate a new equation such as g(x) = f(x) - 10 Now solve g(x) using the fzero function

What is the general function formula?

function(output arguments) = functionname(input arguments)

What function would allow you to make a mesh plot? What is a mesh plot?

mesh(x,y,z) z must be a matrix x and y are independent variables while z is the dependent variable of both x and y. A mesh plot connects values of Z with lines to form the outline of a surface. *It looks like a 3D plane from vectors but without being coloured in, simply the outline.

What is the general form of an anonymous function?

name = @(input arguments) mathematical expression cube = @(x)x^3 >>cube(2) 8 You may have multiple input arguments, so long they have the accompanying mathematical expression name = @(input arguments) mathematical f = @(x,y)x+y >>f(1,1) 2

Knowing the roots of a function how could you get the polynomials coefficients?

p = poly(r) r is a root vector with the roots of a polynomial function

What function would allow you to plot a 3D line?

plot3(x,y,z,'line specifiers','property name',property value') The same way to use this is the same as the plot command just that there is an additional vector. *Remember X Y Z have to be the same length

Which function would allow you to calculate the value of a polynomial?

polyval(p,x) p is a vector with the coefficients of a polynomial so like essentially its a polynomial x is a number or a variable that has an assigned value, or a computable expression, it may be a scalar vector or matrix, at which it is performed element wise *Essentially its just a function with the first argument being f(x) and the second parameter being the x's and it would yield a vector with the values pertaining to the calculations.

What command could allow you to control how you look at a 3D plot?

view(az,el) or view([az el]) AZ stands for azimuth, it is the angle in degrees that is in the xy plane. The angle starts from *(0,-1), and positive as it moves CCW, so (1,0) is going in the positive direction. El - Elevation, it is the angle of elevation above the X,Y plane. Positive in the direction towards upwards in the Z-Axis

What function would enable you to find the root of a function that crosses the X-AXIS, it may be nonlinear, not a polynomial otherwise use roots.

x = fzero(function, x0) Essentially the way fzero function works is such that it determines when the function changes from positive to negative, thus us how its not really a root but when it crosses the x-axis The X is the solution, The function represents what function is to be solved X0 represents a value that is approximated close to where the function crosses the X- Axis

What function could allow you to calculate the numerical integral between limits using 'adaptive Simpson method'?

x = quad(function,a,b) function is entered as a string or with a variable a,b is the limits of the integral; the integral from A to B *Make sure it does not approach a vertical in the interval [A B] an integral can't be calculated for this portion of the graph

What function could allow you to calculate the numerical integral between limits using 'adaptive Lobatto method?'

x = quadl(function,a,b) It is essentially the same as x = quad except there is a lower case' L' after the word quad; *Use this for high accuracies and smoother integrals

What function could allow you to perform integration of a function that has data points?

x = trapz(m,n) *Uses a trapezoid method of numerical integration The vectors X and Y must be the same length X must be in an increasing order

How could you use the view command to get a 2D look such as top view? side view? from X-Z or side view from Y-Z?

x-y top view: view(0,90) x-z side view: view (0,0) y-z side view: view(90,0)

What function would allow you to perform interpolation?

yi = interp1(x,y,xi,'method')

What technique could you use to get the initial x0 value?

you should plot the function, using plot(x,y) and then approximate where the value is that crosses the x-axis

How could you change the surface shading of a 3D mesh or surface plot? How could you change the colour of the plot?

By utilizing the shading command and colour command. Run your 3D plot then afterwards type: shading flat or shading interp the default is shading faceted You can also edit colour like that by using the colormap function colormap(gray) colormap(hot) colormap(cool)

Explain how to use one argument one result function

Alright i feel like this is the way it works: function x = Yo(n) x = (n - 29) end >>Yo(29) 0 Remember, the variable next to the word function is your output argument, Thus when you enter a value for your input argument it works the function then displays the output which in this case is x (cuz it was defined as the output when the function was made)

Explain how the no argument no result function works.

Essentially the function looks as such: function functionname ex: function why disp('g') end >>why g With this, every time you call the function it displays the code that was defined in the function line

Explain the one argument, no result simple function

Essentially this may be used f you want to assign a certain number to the variable when it is used. Shown in this example below: function why(n) for k =1:1:n fprintf('yO') end >>why(3) yOyOyO

Describe how one argument two results function works.

Essentially this works the same way as the one argument one result functionality except now we have two results function [c,k] = stock(f) c = f-32*5/9; k=c+273.15; end >>stock(5) *yields what c and k equals in that order*

Explain how multiple arguments and one result works.

Essentially you have a function like this: function a = hey (1,2,3) a = 1 * 2 /3 + 2*1 end Now when you enter your input values for hey(1,2,3) it will yield the value for a. Note the order of arguments is important when it comes to this situation, the input arguments when defining and using the function must be the same in order for the function to work effectively and properly.


संबंधित स्टडी सेट्स

National Topic Tester - Transfer of Property

View Set

Final Test (Module Quizzes Practice)

View Set

Exploring Medical Terminology - Chapter 16 Endocrine System

View Set

chapter 8 sociology, chapter 10 sociology, Chapter 11 sociology, chapter 12 sociology, chapter 15 sociology, chapter 16

View Set

Chapter 12 evolve questions cancer biology

View Set

Sociology: Social Stratification/Global Stratification

View Set