why do i get '' Error using / Arguments must be numeric, char, or logical.'' for the line where i have f=

50 次查看(过去 30 天)
L = 2;
N = 500;
a = 0;
b = L;
Ra = 300;
Rb = 400;
h = (b-a)/N;
k = @(xj) (5 + (1/6)*xj.^2);
xj = (a+h):h:(b-h);
A = zeros(N-1, N-1);
for i = 2:(N-2)
A(i,i-1)=-1/h^2;
A(i,i) = 2/h^2;
A(i,i+1)=-1/h^2;
end
A(1,1)=2/h^2;
A(1,2)=-1/h^2;
A(N-1,N-2)=-1/h^2;
A(N-1,N-1)=2/h^2;
f = [(1/k)*300*exp(-(( xj - (L/2)).^2))]';
f(1) = (1/k)*300*exp(-(( 0.0080 - (L/2))^2))+(Ra/h^2);
f(N-1)=(1/k)*300*exp(-(( L-0.0080 - (L/2))^2))+(Rb/h^2);
T = A\f;
T=[300, T' , 400];
x=[0:h:2];
plot( x, T)
MaxT=max(T')

采纳的回答

Dave B
Dave B 2021-10-9
You get this error on the line:
f = [(1/k)*300*exp(-(( xj - (L/2)).^2))]';
because you're trying to perform the division 1/k, but k is a function handle.
You defined k as:
k = @(xj) (5 + (1/6)*xj.^2);
This says 'take an input xj and then use that input in the equation'
Maybe you wanted:
f = [(1./k(xj))*300.*exp(-(( xj - (L/2)).^2))]';
I'd also suggest that you consider changing the definition of k to use a different variable name to make more clearly differentiate k's local variable and the outer xj.
I'm also not sure what you intended for the next two lines (which look like scalars so maybe should take in xj(1) and xj(N-1)?
  3 个评论
Dave B
Dave B 2021-10-9
did you catch the two places where I added a . to your code? I'm guessing you want element-wise multiplication and division...

请先登录,再进行评论。

更多回答(1 个)

Ahmad A
Ahmad A 2023-1-18
Error evaluating 'InitFcn' callback of block_diagram 'imfp'.
Callback string is 'f=50;
Ns=(120*f)/P;
w=2*pi*0;
Lls=0.754/1000;
Llr=0.754/1000;
Lm=24/1000;
W=(2*pi*Ns*P)/120;
Vp=230*sqrt(2);
Rr=0.953;
Rs=1.5856;
P=4; J=0.089;
Vdc=500;
ts=10e-6;
Ls=Lm+Lls;
Lr=Lm+Llr;'
Caused by: Arguments must be numeric, char, or logical.
in sumulink for induction motor I get this error, would you please help me?

类别

Help CenterFile Exchange 中查找有关 Get Started with Optimization Toolbox 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by