# Undefined variable or function 'f'

1 view (last 30 days)
Allen Zhong on 19 Jan 2020
Answered: Kaashyap Pappu on 23 Jan 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);
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 CommentsShowHide 1 older comment
Stephan on 19 Jan 2020
How do you call this function?

Kaashyap Pappu on 23 Jan 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!