フィルターのクリア

Multiple functions working together?

2 ビュー (過去 30 日間)
Michael Vaughan
Michael Vaughan 2020 年 9 月 24 日
コメント済み: Michael Vaughan 2020 年 9 月 24 日
here is my code in a script coding window:
function [n] = n(x)
syms q
[n]=(q^(x/2)-q^(-x/2))/(q^(1/2)-q^(-1/2));
end
function d=d(x)
d=n(x+1)
end
I then save this and go to the command window and type in d(3), which I would like the output to be equal to n(4), but instead I get this:
Index exceeds the number of array elements (1).
Error in sym/subsref (line 870)
R_tilde = builtin('subsref',L_tilde,Idx);
What the heck is going on!!? I'm new to this, help appreciated!

採用された回答

Star Strider
Star Strider 2020 年 9 月 24 日
MATLAB is interpreting:
d(3)
as indexing into the third element of ‘d’.
Run:
which d -all
from a script or your Command Window to see if MATLAB can locate the ‘d’ function in the search path (preferably on your user path).

その他の回答 (1 件)

David Hill
David Hill 2020 年 9 月 24 日
syms q
n=@(x)(q^(x/2)-q^(-x/2))/(q^(1/2)-q^(-1/2));
d=@(x)n(x+1);
  1 件のコメント
Michael Vaughan
Michael Vaughan 2020 年 9 月 24 日
what does the (x) do after the @ symbol???? Is it necessary? I seem to be giving functions handles without including that and it works fine

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

カテゴリ

Help Center および File ExchangeFunction Creation についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by