Problem with plotting X @(theta)

1 view (last 30 days)
insaf
insaf on 19 Dec 2018
Commented: madhan ravi on 22 Dec 2018
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

Answers (2)

Star Strider
Star Strider on 19 Dec 2018
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 Comments
Star Strider
Star Strider on 21 Dec 2018
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 on 22 Dec 2018
Anytime :) , second Star Striders point.

Sign in to comment.


madhan ravi
madhan ravi on 19 Dec 2018
Edited: madhan ravi on 19 Dec 2018
str2double() % to convert string to double and then plot
  16 Comments
insaf
insaf on 20 Dec 2018
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 on 20 Dec 2018
so see Star Striders answer

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!