How to plot a function with 1x1 sym value
3 views (last 30 days)
Show older comments
I want to plot T(OMEGA):
T=real(1i*n*alfak*(besselj(np+1,alfak))^2*(conj(A3)*B3-A3*conj(B3)))
where:
- np is known
- n is known
- alfak is known
- besselj(np+1, alfak) is the bessel function of the fisrt kind of order np+1
But A3 and B3 depends on OMEGA and they appears as 1x1 sym in the workspace.
I used this code:
fplot(@(OMEGA) T)
grid on
but this message appears on the command window:
Warning: Function behaves unexpectedly on array inputs. To improve performance, properly vectorize your function to return an output with
the same size and shape as the input arguments.
> In matlab.graphics.function.FunctionLine>getFunction
In matlab.graphics.function.FunctionLine/updateFunction
In matlab.graphics.function.FunctionLine/set.Function_I
In matlab.graphics.function.FunctionLine/set.Function
In matlab.graphics.function.FunctionLine
In fplot>singleFplot (line 232)
In fplot>@(f)singleFplot(cax,{f},limits,extraOpts,args) (line 191)
In fplot>vectorizeFplot (line 191)
In fplot (line 161)
In Untitled2 (line 103)
Warning: Error updating FunctionLine.
The following error was reported evaluating the function in FunctionLine update: Unable to convert expression into double array.
which is the problem? How can I solve it?
0 Comments
Answers (1)
Walter Roberson
on 12 May 2020
Replace
fplot(@(OMEGA) T)
with
fplot(T)
Remember that fplot will be passing in a vector of particular values that it wants to evaluate the function at, but no matter what size of input it passes in, you are always returning the scalar value T, which is a symbolic expression involving the unresolved variable OMEGA .
When you use @(VARIABLE) EXPRESSION where EXPRESSION is a symbolic expression involving VARIABLE, then MATLAB will not substitute the parameter passed in for the value of the variable. You could, though,
fplot( @(omega) subs(T, OMEGA, omega) )
but you might as well just
fplot(T)
See Also
Categories
Find more on Numbers and Precision in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!