Undefined variable or function 'f'

1 visualización (últimos 30 días)
Allen Zhong
Allen Zhong el 19 de En. de 2020
Respondida: Kaashyap Pappu el 23 de En. de 2020
Hi, I'm trying to resolve an error in my matlab code, which is trying to find the inductance and resistance through voltage and current. Here are my codes:
function [b,m,db,dm] = wRegression(x, y, dy)
% WREGRESSION [b,m,db,dm] = wRegression(x, y, dy)
% Written by: Allen Zhong
% takes x and y values, and uncertainies on y (dy), and outputs the slope
% (m), intercept (b), slope error (dm), and intercept error (db) for the
% linear regression (y = mx + b)
%define the variable w to simplify expressions
w = 1./(dy.^2);
D = addUp(w).*addUp(w.*x.^2)-(addUp(w.*x)).^2;
b = (addUp(w.*x.^2).*addUp(w.*y)-addUp(w.*x).*addUp(w.*x.*y))/D; %Computes y intercept
m = (addUp(w).*addUp(w.*x.*y)-addUp(w.*x).*addUp(w.*y))/D; %Computes slope
db = sqrt(addUp(w.*x.^2)/D); %Computes uncertainties in intercept
dm = sqrt(addUp(w)/D); %Computes uncertainties in slope
end
function [L, R, dL, dR] = findInductanceAndResistance(f, V, I, dV, dI)
wsq = (2.*pi.*f).^2;
Z2 = (V./I).^2;
dzSqrd = ((Z2(V+dV,I)-Z2(V,I)).^2+(Z2(V,I+dI)-Z2(V,I)).^2).^0.5;
[Rsq,Lsq,dLsq,dRsq] = wRegression(wsq,Z2,dzSqrd);
L= (Lsq).^0.5;
R = (Rsq).^0.5;
dR = (Rsq+dRsq).^0.5-(Rsq).^0.5;
dL = (Lsq+dLsq).^0.5-(Lsq).^0.5;
end
For 'findInductanceAndResistance', I can't seem to get it working as there is always an unresolved 'undefined function 'f''. Any help and assistance would be appreciated.
  2 comentarios
Star Strider
Star Strider el 19 de En. de 2020
Siunce ‘f’ is an agrument (that appears to be a frequency vector), it must specifically be passed to the function. Functions written using the function declaration (as opposed to anonymous functions) do not inherit variables from the workspace.
Stephan
Stephan el 19 de En. de 2020
How do you call this function?

Iniciar sesión para comentar.

Respuestas (1)

Kaashyap Pappu
Kaashyap Pappu el 23 de En. de 2020
The variable ‘f’ needs to be passed as an input argument in the function call. As has been mentioned, each function has its own workspace and therefore will not access variables from the base workspace. More information can be found here.
If ‘f’ is a custom function, you may have to make sure the function is saved in the same directory while calling ‘findInductanceAndResistance’.
Hope this helps!

Categorías

Más información sobre Mathematics en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by