Problem with plotting X @(theta)

2 Ansichten (letzte 30 Tage)
insaf
insaf am 19 Dez. 2018
Kommentiert: madhan ravi am 22 Dez. 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

Antworten (2)

Star Strider
Star Strider am 19 Dez. 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 Kommentare
Star Strider
Star Strider am 21 Dez. 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 am 22 Dez. 2018
Anytime :) , second Star Striders point.

Melden Sie sich an, um zu kommentieren.


madhan ravi
madhan ravi am 19 Dez. 2018
Bearbeitet: madhan ravi am 19 Dez. 2018
str2double() % to convert string to double and then plot
  16 Kommentare
insaf
insaf am 20 Dez. 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 am 20 Dez. 2018
so see Star Striders answer

Melden Sie sich an, um zu kommentieren.

Community Treasure Hunt

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

Start Hunting!

Translated by