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 CenterFile Exchange에서 Octave에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by