How do you add two functions in Matlab?

How do you add two functions in Matlab?

Try this:

  1. w=2*pi*1.0E+5;
  2. s1=@(t) cos(t/2). *cos(w*t) . *((0 <= t) & (t <= pi));
  3. s12=@(t) sin(t/2). *cos(w*t) . *((0 <= t) & (t<= pi));
  4. % Plot 500 points between -. 2 and 4.
  5. t = linspace(-. 2, 4, 500);
  6. z = s1(t) + s12(t);
  7. % Set up figure properties:
  8. % Enlarge figure to full screen.

How do you multiply elements in a matrix in Matlab?

B = prod( A ) returns the product of the array elements of A .

  1. If A is a vector, then prod(A) returns the product of the elements.
  2. If A is a nonempty matrix, then prod(A) treats the columns of A as vectors and returns a row vector of the products of each column.
  3. If A is an empty 0-by-0 matrix, prod(A) returns 1 .

How do you add two functions?

Operations on Functions: Adding and Subtracting Functions

  1. Addition. We can add two functions as: (f + g)(x) = f(x) + g(x) Example:
  2. Subtraction. We can subtract two functions as: (f – g)(x) = f(x) – g(x) Example:
  3. Multiplication. (f•g)(x) = f(x)•g(x) Example: f(x) = 3x – 5 and g(x) = x.
  4. Division. (f/g)(x) = f(x)/g(x) Example:

How do you multiply elements in a matrix?

Matrix Multiplication

  1. When you multiply a matrix by a number, you multiply every element in the matrix by the same number.
  2. For example, if x is 5, and the matrix A is:
  3. Then, xA = 5A and.
  4. In the example above, every element of A is multiplied by 5 to produce the scalar multiple, B.

How to multiply two functions in MATLAB Stack Exchange?

If you want a purely numerical result the MATLAB trick is to use a dot . like: f (x).*g (x) It takes care of pointwise multiplication for matrices. Thanks for contributing an answer to Computational Science Stack Exchange!

How do you multiply arrays in MATLAB times?

Multiplication – MATLAB times .* times, .* C = A.*B multiplies arrays A and B by multiplying corresponding elements. The sizes of A and B must be the same or be compatible. If the sizes of A and B are compatible, then the two arrays implicitly expand to match each other.

Which is an example of multiplication in MATLAB?

example. C = A.*B multiplies arrays A and B by multiplying corresponding elements. The sizes of A and B must be the same or be compatible. If the sizes of A and B are compatible, then the two arrays implicitly expand to match each other. For example, if one of A or B is a scalar, then the scalar is combined with each element of the other array.

How do you multiply two vectors in MATLAB?

Create two vectors, A and B, and multiply them element by element. A = [1 0 3]; B = [2 3 7]; C = A.*B. C = 1×3 2 0 21.