create a 1 x 100 vector of x values according to -15<x<0 and use elementwise operators to create 3 more 1x100 vectors in matlab

To create a 1x100 vector of x values according to -15<x<0, we can use the linspace function or the colon operator. Here's an example using the colon operator:

main.m
x = -15: -15/99: 0;
20 chars
2 lines

This creates a 1x100 evenly spaced vector of x values starting from -15 and going up to 0.

To create 3 more 1x100 vectors using elementwise operators, we can use the +, -, *, and / operators to perform elementwise addition, subtraction, multiplication, and division. For example:

main.m
y1 = sin(x).*cos(x);
y2 = exp(x) + 2*cos(x);
y3 = 3./(x+15).^2;
64 chars
4 lines

The first line uses elementwise multiplication of sin(x) and cos(x) to create a new vector y1. The second line uses elementwise addition of exp(x) and 2*cos(x) to create a new vector y2. The third line uses elementwise division and exponentiation to create a new vector y3.

By using vectorization and elementwise operators, we can create these 4 vectors efficiently in a single programmatic step.

gistlibby LogSnag