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

45 visualizaciones (últimos 30 días)
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')

Respuesta aceptada

Dave B
Dave B el 9 de Oct. de 2021
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 comentarios
Dave B
Dave B el 9 de Oct. de 2021
did you catch the two places where I added a . to your code? I'm guessing you want element-wise multiplication and division...

Iniciar sesión para comentar.

Más respuestas (1)

Ahmad A
Ahmad A el 18 de En. de 2023
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?

Categorías

Más información sobre Get Started with Optimization Toolbox en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by