Hello, I am trying to plot the a graph and my syntax is as follows (Saved in A3):
x = [-2:0.01:2]
y = f3(x)
plot (x,y,'k-')
I have declaterd the function in f3.m file as follows:
function y=f3(x)
y=3*x^4-2*x^2-2
I am getting the following error and I don't understand what did I do wrong.
Error using ^
Inputs must be a scalar and a square matrix.
To compute elementwise POWER, use POWER (.^) instead.
Error in f3 (line 2)
y=(3*x^4-2*x^2-2)
Error in A3 (line 12)
y = f3(x)
I don't want to use elementwise power. If the above syntax is wrong, please let me know what is wrong and what can be done to fix it.
Thanks you very much for your assistance.

 採用された回答

Roger Stafford
Roger Stafford 2013 年 10 月 6 日

0 投票

You are attempting to use matrix power on a row vector and that is not an allowed syntax. As the error message clearly states, it can only be applied to square matrices. You must use the .^ power for elements of your row vector. If you don't want to use this "elementwise power", you need to define just what kind of operation you have in mind.

1 件のコメント

Ravi
Ravi 2013 年 10 月 6 日
Thank you for your help Roger.

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File Exchange2-D and 3-D Plots についてさらに検索

質問済み:

2013 年 10 月 6 日

コメント済み:

2013 年 10 月 6 日

Community Treasure Hunt

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

Start Hunting!

Translated by