Undefined variable or function 'f'
1 view (last 30 days)
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
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);
R = (Rsq).^0.5;
dR = (Rsq+dRsq).^0.5-(Rsq).^0.5;
dL = (Lsq+dLsq).^0.5-(Lsq).^0.5;
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.
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!