## I'm not sure what I'm doing wrong that gives me a error

Umut Ayyildiz

### Umut Ayyildiz (view profile)

さんによって質問されました 2019 年 2 月 4 日

### Rik (view profile)

さんによって コメントされました 2019 年 2 月 5 日
The question is:
The maximum height h achieved by an object thrown with a speed v at an angle θ to the horizontal, neglecting drag, is
h =(v^2*(sin(θ))^2)/(2g)
Create a table showing the maximum height for the following values of v and θ:
v = {10,12,14,16,18,20}m/s, θ = {50,60,70,80}
The rows in the table should correspond to the speed values, and the columns should correspond to the angles.I have this so far
v=[10, 12, 14, 16, 18, 20]
t=[50, 60, 70, 80]
g=9.8
h=((v^2).*(sind(t)^2))/(2g)
After I run it, I get this error:
Invalid expression. Check for missing
multiplication operator, missing or
unbalanced delimiters, or other syntax
error. To construct matrices, use brackets

#### 0 件のコメント

サインイン to comment.

## 3 件の回答

on 4 Feb 2019
Edited by Rik

### Rik (view profile)

on 5 Feb 2019

You should transpose your speed vector, so it has one value per row. If you then change your expression to the one below, the implicit expansion will make sure the end result is a matrix.
v=[10, 12, 14, 16, 18, 20]';
t=[50, 60, 70, 80];
g=9.8;
h=((v.^2).*(sind(t).^2))./(2*g)

Umut Ayyildiz

### Umut Ayyildiz (view profile)

on 5 Feb 2019
This code still gives me the same error. I instead changed the code to
v=[10, 12, 14, 16, 18, 20]
t=[50; 60; 70; 80]
g=9.8
h=(v.^2.*(sind(t).^2))./(2*g)
I just added semicolons, I'm not sure what they do but I got an output.
Rik

### Rik (view profile)

on 5 Feb 2019
If you copy my code exactly, it will return an output.
What your code will do is create a row vector v and a column vector t, resulting in a 4x6 matrix h, which means that every row corresponds to a value of theta and every column corresponds to a value of v, which is the opposite of your assignment.
There are two delimiters in Matlab for making arrays, the comma and the semicolon. The comma separates columns, and the semicolon starts a new row. You can either input a vector as a column vector, or input it as a row vector and then transpose it (like I did with v).

サインイン to comment.

### Kevin Phung (view profile)

on 4 Feb 2019

your time vector and velocities are not the same length.. I'm guessing you're incrementing by 10.
you're also missing some element wise operations (indicated with a period) and youre missing a multiplication for 2*g.
so:
v=[10, 12, 14, 16, 18, 20]
t=[50, 60, 70, 80, 90, 100]
g=9.8
h=((v.^2).*(sind(t).^2))/(2*g)
should work and give you an array for height

#### 0 件のコメント

サインイン to comment.