Problem with plotting X @(theta)

2 visualizzazioni (ultimi 30 giorni)
insaf
insaf il 19 Dic 2018
Commentato: madhan ravi il 22 Dic 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

Risposte (2)

Star Strider
Star Strider il 19 Dic 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 Commenti
Star Strider
Star Strider il 21 Dic 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 il 22 Dic 2018
Anytime :) , second Star Striders point.

Accedi per commentare.


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

Accedi per commentare.

Community Treasure Hunt

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

Start Hunting!

Translated by