![]() Your own plots may look slightly different. PS: The above plots were made in octave rather than in matlab, because I don't have matlab at home. Type help plot at the matlab terminal to see more options for the plot command. If you wanted to see just the individual points of your array instead, you can specify this as the third argument: plot(x, y, 'o') You can now plot this using the plot command, which takes two arrays of the same size and plots all points in the first array against their equivalent points in the second array, as (x,y) pairs: plot( x, y ) Īs you can see, matlab 'connects' the points by default. The result is an array y of the same size as x. Simplify Symbolic Expressions Using Live Editor Task. Simplifying symbolic expressions, including assumptions and additional options. Extract Numerators and Denominators of Rational Expressions. With that in mind, you can now calculate your f(x) for each point in the array x, by using elementwise operations: y = exp( sin(x).^3 ) + x.^6 - 2*(x.^4) - x.^3 - 1 Several functions are available to manipulate expressions. How do I write Matlab code using functions to make a rotation on an image THis is all Ive got so far, and Im probably way off. Therefore to raise all elements of the array x to the power of 6, you would do x. Learn more about image processing, rotation, tform, iwarp MATLAB. By convention, matlab uses "dot-operators" to denote "elementwise" operations, as opposed to 'undotted' ones denoting primarily "matrix" operations. Now that you have your array x you can perform operations on it. % see the contents of your array, remove it at the end. % Note: the ' ' at the end suppresses output if you want to So instead I would suggest you create an array of values between, and obtain the value of y for each of them, which in matlab can be done as a single operation because it's good at working with arrays and performing such 'vectorized' operations: x = % Create an array of values from -2 to 2, with a step of 0.1 You could use fplot with an anonymous function as Neo suggested, but I find that beginners find that confusing. ![]() The sin function, similarly, if given an array of numbers, will calculate the sin for each of those numbers, and return an array of the same shape as its input. If you pass an array to exp, it will perform this function "elementwise", and return appropriately. While you could in theory compute e and then use the power operator ( ^ in matlab) to raise e to that power accordingly, this is in fact a less precise way of calculating the exponential function, and therefore matlab provides the exp function for that purpose. ![]() The sinusoid is plotted for values of x between 0 and 2 p the step between consecutive values of x is 0.1. raising e to the power of x is known as the exponential function. MATLAB Plotting Trigonometric Functions Type at the Matlab prompt: x 0:0.1: 2pi ysin (x) plot (x,y) xlabel (angle (rad)) ylabel (sine) title (y sin (x)) You will see a sinusoid on the graphics window. The e is known as Euler's constant, where e ~ 2.71828. Let's cover all the points in no particular order:
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |