ERROR'Not enough input arguments.'

This is my code:
function y=gx(x)
y=(5.*x-6)./((x-1.3).^2+0.03)+(9.*x)./(x.^3+0.04)-(x-0.5)./((x-0.98).^2+0.07)
end
the error is:
Not enough input arguments.
Error in gx (line 4)
y=(5.*x-6)./((x-1.3).^2+0.03)+(9.*x)./(x.^3+0.04)-(x-0.5)./((x-0.98).^2+0.07)
Can anyone help me?

回答 (1 件)

Star Strider
Star Strider 2019 年 12 月 25 日

0 投票

Apparently, you are calling ‘gx’ without an input argument, perhaps by using the green Run arrow in the editor. Functions that are written with input arguments must always be supplied with them in calls to them.
When I run it from a script:
x = 42;
y = gx(x)
it runs without error and produces:
y =
0.103589181681349
Call it from a script (or the Command Window) with an argumetnt, and it should do what you want.

4 件のコメント

cosine Zheng
cosine Zheng 2019 年 12 月 26 日
編集済み: cosine Zheng 2019 年 12 月 26 日
If I just want to get the plot of gx. How should I do from a script?
Star Strider
Star Strider 2019 年 12 月 26 日
This is how I would do it:
xv = linspace(-10, 10, 250);
figure
plot(xv, gx(xv))
grid
Define ‘xv’ to be the range you want.
Also, put a semicolon (;) at the end of the ‘y’ assignment in ‘gx’ to keep it from printing the results of its calculations to the Command Window.
cosine Zheng
cosine Zheng 2019 年 12 月 26 日
Oh,thanks for your answering.
Star Strider
Star Strider 2019 年 12 月 26 日
My pleasure.
If my Answer helped you solve your problem, please Accept it!

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

カテゴリ

ヘルプ センター および File ExchangeStartup and Shutdown についてさらに検索

質問済み:

2019 年 12 月 25 日

コメント済み:

2019 年 12 月 26 日

Community Treasure Hunt

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

Start Hunting!

Translated by