## 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 件の回答

2019 年 2 月 4 日

### Rik (view profile)

2019 年 2 月 5 日

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)

2019 年 2 月 5 日
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)

2019 年 2 月 5 日
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)

2019 年 2 月 4 日

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.

### Steven Lord (view profile)

2019 年 2 月 4 日

If you open this code in the MATLAB Editor, you should see that there is a red square in the upper-right corner of the Editor window. That means Code Analyzer has detected an error in your code that will prevent it from running. Below that red square is a red line corresponding to line 4 of the code. If you look closely at line 4, you should see that the g near the end of the line is underlined in red. That's where the error occurs.
If you're multipying two variables together or a number and a variable, you must include the multiplication sign. When you add the * between 2 and g on that line the red underline goes away and the red square turns orange.

#### 0 件のコメント

サインイン to comment.