keep getting an error message saying might be missing a closing bracket, causing invalid syntax at y, but the bracket is there. (line 34)

7 件のコメント

Stephen23
Stephen23 2023 年 5 月 12 日
@Millie Bates: please paste your complete code as text. It is quite possible the the mistake occurs earlier in the code.
@Millie Bates, the request was to post the code as text, not the picture of the code.
Copy and paste your code.
Stephen23
Stephen23 2023 年 5 月 12 日
@Millie Bates: please paste your code as text (as asked). We cannot open an image in the MATLAB editor.
Stephen23
Stephen23 2023 年 5 月 12 日
編集済み: Stephen23 2023 年 5 月 12 日
As Fangjun Jiang observed, this line has several syntax errors, e.g.:
odeFun =@(t,y) [y(2);g*(2*h/R)y(1)/R+3(y(1)/R)^2];
% ^^ scalar numeric cannot be indexed or called
% ^^ missing operator
Did you mean to multiply those terms, or use a delimiter of some kind?
I'm not sure but would adding a multiplication operator define the variable R as another error says that the variable R is unrecognised
Do you mean this?
odeFun =@(t,y) [y(2);g*(2*h/R)*y(1)/R+3*(y(1)/R)^2]
Stephen23
Stephen23 2023 年 5 月 12 日
編集済み: Stephen23 2023 年 5 月 12 日
"would adding a multiplication operator define the variable R as another error says that the variable R is unrecognised "
A multiplication operator does not define its input arguments. It requires its inputs to be already defined, for the simple reason that it is not possible to multiply numeric values that do not exist.
Defining variables is done e.g. by allocating something to that variable or as an input argument to a function.
The variable R is defined as the very first input to your function:
function [outputArg1,outputArg2] = Hemisphere(R,h,T_f)
Are you calling the function with its required inputs?

サインインしてコメントする。

回答 (1 件)

Fangjun Jiang
Fangjun Jiang 2023 年 5 月 12 日
編集済み: Fangjun Jiang 2023 年 5 月 12 日
You can paste the text, instead of attaching a snapshot picture.
I believe there is a mistake in defining the odeFun. There is no operator in front of "y(1)". "3(y(1)" is not valid either.

カテゴリ

ヘルプ センター および File ExchangeEntering Commands についてさらに検索

質問済み:

2023 年 5 月 12 日

編集済み:

2023 年 5 月 12 日

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by