Problem with plotting X @(theta)

2 ビュー (過去 30 日間)
insaf
insaf 2018 年 12 月 19 日
コメント済み: madhan ravi 2018 年 12 月 22 日
Hello there,
I have a function X(theta) defined by two others f(theta) and g(theta). the problem that I have is within plotting the X function. I use fplot command, but it shows me the error: "error: invalid conversion from string to real N-D array error". what does mean this? and how can I properly plot the function I want.
Thank you!
N.B: I use Octave

回答 (2 件)

Star Strider
Star Strider 2018 年 12 月 19 日
Since you did not share your code, I can only guess what the problem is.
First, if you refer to a function within another function, you must call it as a function, just as you would in any other context.
Second, I am not familiar with Octave and its error messages.
Try this:
f = @(theta) sin(theta); % Create Function
g = @(theta) cos(theta); % Create Function
X = @(theta) f(theta) .* g(theta); % Create Function
figure
fplot(X)
grid
  10 件のコメント
Star Strider
Star Strider 2018 年 12 月 21 日
Our pleasure.
It would be nice to know how Octave’s fplot does its calculations. It appears not to to be as robust to row and column orientations as the MATLAB fplot function is.
madhan ravi
madhan ravi 2018 年 12 月 22 日
Anytime :) , second Star Striders point.

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


madhan ravi
madhan ravi 2018 年 12 月 19 日
編集済み: madhan ravi 2018 年 12 月 19 日
str2double() % to convert string to double and then plot
  16 件のコメント
insaf
insaf 2018 年 12 月 20 日
thank you Star Strider for your response, effectively, I noticed the error in defining theta. for the other code using "For", it doesn't work in octave since the "main" function is not defined there. I will search for an equivalent for it in octave, I think it will be easy then to implement a loop "for".
Mr madhan ravi what I'm wondering is the values I got using your code for f and g: as theta is defined in a large interval, f should then be a function of theta, but the code gives me a number! I guess because it calculates the summation along theta and k, while I want it to be just on k, so the f will be a function of theta.
the same thing with g, and x of course.
I hope my problem is clear for you
madhan ravi
madhan ravi 2018 年 12 月 20 日
so see Star Striders answer

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

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by