How to plot a function with 1x1 sym value

20 views (last 30 days)
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?

Answers (1)

Walter Roberson
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)
  1 Comment
Luigi Stragapede
Luigi Stragapede on 12 May 2020
I tried but nothing. I have this message:
Error using fplot>singleFplot (line 227)
Input must be a function or functions of a single variable.
Error in fplot>@(f)singleFplot(cax,{f},limits,extraOpts,args) (line 191)
hObj = cellfun(@(f)
singleFplot(cax,{f},limits,extraOpts,args),fn{1},'UniformOutput',false);
Error in fplot>vectorizeFplot (line 191)
hObj = cellfun(@(f)
singleFplot(cax,{f},limits,extraOpts,args),fn{1},'UniformOutput',false);
Error in fplot (line 161)
hObj = vectorizeFplot(cax,fn,limits,extraOpts,args);
Error in calcolo_grafico_coppia (line 104)
fplot(T)
Do you have other ideas?

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!