Error while plotting function

조회 수: 1 (최근 30일)
Nitheesh S Pillai
Nitheesh S Pillai 2020년 6월 12일
댓글: Rik 2020년 6월 12일
I am new to MATLAB. I wrote the following code:
syms E
L = 2.53805*(10^18)
m2 = 2.6*(10^-23)
c = 1*(10^-16)
%syms m2
syms P Q QE a N1 N2 L1 L2 DEL21 U1 U2 U3 U4
syms residue2
sum1 = 0
sum2 = 0
sum3 = 0
for i = 1:1050
E = .2 + (.001*i);
A = m2/(2*E);
B = a*(E^2);
C = c*(E^5);
DEL21= sqrt(((A-B-C)^2)+(8*((A+B)^2)));
L1 = 0.5*((3*A)+B+C-DEL21);
L2 = 0.5*((3*A)+B+C+DEL21);
N1 = sqrt(((L1-2*A)^2)+2*((A+B)^2));
N2 = sqrt(((L2-2*A)^2)+2*((A+B)^2));
U1 = (L2-2*A)/N2;
U2 = (A+B)/N2;
U3 = (L1-2*A)/N1;
U4 = (A+B)/N1;
P = -4*(U1*U2*U3*U4*((sin(DEL21*L/2))^2));
Q = 380*P;
if (i>=1) && (i<=100)
sum1 = sum1 + Q;
elseif (i>100) && (i<=275)
sum2 = sum2 + Q;
else
sum3 = sum3 + Q;
end
end
residue2 = (45.2 - sum1)^2 + (83.7-sum2)^2 + (22.1-sum3)^2
fplot(@(a) residue2, [10^-20,10^-19])
When I ran the code, I got the following error:
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 237)
In fplot>@(f)singleFplot(cax,{f},limits,extraOpts,args) (line 192)
In fplot>vectorizeFplot (line 192)
In fplot (line 162)
In New_code (line 46)
Warning: Error updating FunctionLine.
The following error was reported evaluating the function in
FunctionLine update: Unable to convert expression into double
array.
Warning: Error updating FunctionLine.
The following error was reported evaluating the function in
FunctionLine update: Unable to convert expression into double
array.
Can someone help me understand what the issue is and how to resolve it?
  댓글 수: 1
Rik
Rik 2020년 6월 12일
This results in a very complicated symbolic expression. What are you trying to do, and why are you trying to do it with syms? If residue2 is a function of a, why isn't it a function?

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Assumptions에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by