How to approximate a multivariable arctan function?
Mostrar comentarios más antiguos
Hi,
let the following function be given:

Is there a way in Matlab to approximate this function as a multivariable (x1,x2,x3,u1) rational polynomial?
lv and bv are positive constants.
x2 should be defined within -pi/4 and pi/4 [rad].
x3 should be defined within (-pi/4) and (pi/4) [rad/sec].
x1 > 0 [meter/sec].
u1 should be defined within (-pi/12) and (pi/12) [rad].
Thanks a lot in advance!
19 comentarios
Jannis Erz
el 18 de Sept. de 2022
Strange that the exponent of x in the denominator of y is m-1 and not m-i ...
I don't see how you want to cope with the multidimensionality of your function. The rational model only has 1 independent variable while your function has 4.
Jannis Erz
el 18 de Sept. de 2022
Ok.
Then evaluate your function for a number of points over the relevant intervals and make a least-square fit for the coefficient of the rational function you want to use.
A MATLAB program you could use for this task is lsqcurvefit.
But atan has a very restricted codomain. I wonder how rational functions in 4 variables should be able to approximate it.
Hi @Jannis Erz
Do you think it is feasible to work out something like this
for the approximation of

where

and then using the Symbolic Math Toolbox to transform it into a your desired Rational Polynomial function?

Jannis Erz
el 19 de Sept. de 2022
Jannis Erz
el 19 de Sept. de 2022
Torsten
el 19 de Sept. de 2022
fun = @(p,alpha)(p(1)*alpha.^3+p(2)*alpha.^2+p(3)*alpha)./(alpha.^4+p(4)*alpha.^2+p(5));
instead of
fun = @(p,alpha)((p(1).*alpha.^3+p(2).*alpha.^2+p(3).*alpha)./((alpha.^4)+p(4).*alpha.^2)+p(5));
The poles will make trouble.
Maybe you can formulate a constraint on p(4) and p(5) such that the roots are outside the interval of approximation. Then use fmincon instead of lsqcurvefit and define this constraint in the nonlcon function.
% Lateral Parameters
F_z0 = 3; % Nominal vertical wheel Load [kN]
F_z = 3000; % Actual vertical wheel load [kN]
muy0 = 1;
Cy = 1.3;
c1 = 8;
c2 = 1.33;
Ey = -1;
alpha_deg = [-20:0.5:20];
alpha = deg2rad(alpha_deg);
for idx1 = 1:length(alpha)
Dy0 = muy0 * (F_z/1000);
CFa0 = c1*c2*F_z0*sin(2*atan((F_z/1000)/(c2*F_z0))); % Cornering Stiffness [kN/rad]
By0 = CFa0/(Cy*Dy0);
df_z = ((F_z/1000)-F_z0)/F_z0; % Normalized change in vertical load % Normalized change in vertical load
F_q(idx1) = (Dy0 * sin(Cy*atan(By0*(alpha(idx1)) - Ey*(By0*(alpha(idx1))-atan(By0*(alpha(idx1)))))))*1000; % Pure Lateral Force [N]
end
fun = @(p)(p(1)*alpha.^3+p(2)*alpha.^2+p(3)*alpha)-F_q.*(alpha.^4+p(4)*alpha.^2+p(5));
fun1 = @(p)(p(1)*alpha.^3+p(2)*alpha.^2+p(3)*alpha)./(alpha.^4+p(4)*alpha.^2+p(5));
%fun = @(p,alpha)((p(1).*alpha.^3+p(2).*alpha.^2+p(3).*alpha)./((alpha.^4)+p(4).*alpha.^2)+p(5));
% Rational Function to approximate Lateral Tyre Force
p0 = [0.1,0.1,0.1,0.1,0.1];
format long
p = lsqnonlin(fun,p0)
rad2deg(roots([1 0 p(4) 0 p(5)]))
plot(rad2deg(alpha),F_q,'o')
hold on
plot(rad2deg(alpha),fun1(p))
xlabel('Tyre Side Slip Angle [deg]')
ylabel('Pure Lateral Tyre Force [N]')
legend('Pacejka Data','Fitted exponential')
% Lateral Parameters
F_z0 = 3; % Nominal vertical wheel Load [kN]
F_z = 3000; % Actual vertical wheel load [kN]
muy0 = 1;
Cy = 1.3;
c1 = 8;
c2 = 1.33;
Ey = -1;
alpha_deg = [-20:0.1:20];
alpha = deg2rad(alpha_deg);
for idx1 = 1:length(alpha)
Dy0 = muy0 * (F_z/1000);
CFa0 = c1*c2*F_z0*sin(2*atan((F_z/1000)/(c2*F_z0))); % Cornering Stiffness [kN/rad]
By0 = CFa0/(Cy*Dy0);
df_z = ((F_z/1000)-F_z0)/F_z0; % Normalized change in vertical load % Normalized change in vertical load
F_q(idx1) = (Dy0 * sin(Cy*atan(By0*(alpha(idx1)) - Ey*(By0*(alpha(idx1))-atan(By0*(alpha(idx1)))))))*1000; % Pure Lateral Force [N]
end
fun = @(p)sum(((p(1)*alpha.^3+p(2)*alpha.^2+p(3)*alpha)./(alpha.^4+p(4)*alpha.^2+p(5))-F_q).^2);
fun1 = @(p)(p(1)*alpha.^3+p(2)*alpha.^2+p(3)*alpha)./(alpha.^4+p(4)*alpha.^2+p(5));
p0 = [0.1,0.1,0.1,0.1,0.1];
options = optimset('MaxFunEvals',100000,'MaxIter',100000);
format long
p = fmincon(fun,p0,[],[],[],[],[],[],@nonlcon,options)
rad2deg(roots([1 0 p(4) 0 p(5)]))
plot(rad2deg(alpha),F_q,'o')
hold on
plot(rad2deg(alpha),fun1(p))
xlabel('Tyre Side Slip Angle [deg]')
ylabel('Pure Lateral Tyre Force [N]')
legend('Pacejka Data','Fitted exponential')
function [c,ceq] = nonlcon(p)
c = p(4)^2/4-p(5);
ceq = [];
end
Jannis Erz
el 20 de Sept. de 2022
Torsten
el 20 de Sept. de 2022
One way to avoid real poles in the interval of interest is to make all roots of the denominator complex. That's what I did. Of course, this is quite arbitrary and might exclude a better solution. Feel free to experiment.
Jannis Erz
el 23 de Sept. de 2022
Torsten
el 23 de Sept. de 2022
Your problem is overfitted.
As you can see in MATLAB's rational models section, one of the parameters to be fitted must be normalized to 1.
Jannis Erz
el 23 de Sept. de 2022
No, in the same way as the rational polynomials in MATLAB are defined - by setting p(10) = 1 and fitting only 9 parameters.
Note that if p(1),...,p(10) is a solution for the Least-squares problem, then also p(1)*c,p(2)*c,...,p(10)*c is a solution for every constant c not equal to 0. This is prohibited by normalizing one of the parameters to 1.
Jannis Erz
el 24 de Sept. de 2022
Respuestas (1)
John D'Errico
el 18 de Sept. de 2022
Editada: John D'Errico
el 18 de Sept. de 2022
@Sam Chak has suggested an interesting idea in a comment. However, while it is not a bad idea at first glance, I suspect it will be problematic. The issue is, that classic atan series is not very strongly convergent. Expect to need many terms before you get anything good. And that means the polynomial approximation will be poor at best.
For example, how many terms do you need for convergence as a function of x to k significant digits, in the simple atan series?
For example, when x == 1, how many terms are required? We can look at it easily, since that is just the Leibniz formula for pi/4. Thus...
N = 0:1000;
S = mod(N+1,2)*2 - 1;
approx = cumsum(S./(2*N+1));
truth = pi/4;
semilogy(N,abs(approx - truth))
grid on
So we need thousands of terms for convergence near x==1.
However, if you can use range reduction methods to force the argument x to the atan to be in a small interval near zero, you get much faster convergence. The problem is, that in itself may take some work, and it is not at all trivial to get good convergence.
Instead, you may gain from using a direct rational polynomial approximation, perhaps something like those found in the classic, by JF Hart, et al, "Computer Approximations". (Start reading around page 120 in my edition from 1978. The tables there give some pretty good approxmations, though they still employ range reduction.)
Note: Even though Hart is an old text, it is still a book I love dearly, but that might apply only to a real gearhead numerical analyst like me. I think I recall it is available as a Dover reprint.
7 comentarios
Sam Chak
el 19 de Sept. de 2022
@John D'Errico, thanks for the heads-up. @Jannis Erz has mentioned about using the approximated Rational Polynomial function for some kind of Lyapunov Stability analysis.
Since the range for
and
are given, I guess that the stability analysis may be applied on the vicinity of some equilibrium points like
and
, and therefore
.Does @Jannis Erz need to approximate until
for the purpose of showing the stability proof around the equilibrium points?
Jannis Erz
el 19 de Sept. de 2022
John D'Errico
el 19 de Sept. de 2022
Editada: John D'Errico
el 19 de Sept. de 2022
@Sam Chak - the point is, there are arguably multiple ways to generate a rational polynomial approximation to a function. However, if you START with a poorly convergent Taylor series, you will likely not be happy with the result. This is my fear, and why I would suggest using a rational polynomial approximation itself for the atan which can have better properties over the desired domain.
@Jannis Erz - You can learn a lot from the Hart text. It remains one of the books I leave on my shelf next to my desk. (Abramowitz & Stegun is another, where my copy has tabs attached to the sections I have used regularly over the years.)
Bruno Luong
el 19 de Sept. de 2022
Editada: Bruno Luong
el 19 de Sept. de 2022
@John D'Errico: not necessary. It is well known that Padé fractional series converges better much than Taylor series, but the Padé series is derived directly from the Taylor series.
That being say, the best approximation on a given interval is just from numerical calculation.
OP has changed the function to:

F_z0 = 3;
F_z = 3000;
muy0 = 1;
Dy0 = muy0*(F_z/1000);
c1 = 8;
c2 = 1.33;
CFa0 = c1*c2*F_z0*sin(2*atan((F_z/1000)/(c2*F_z0)));
Cy = 1.3;
By0 = CFa0/(Cy*Dy0);
Ey = -1;
alpha_deg = linspace(-20, 20, 401);
alpha = deg2rad(alpha_deg);
Fq = 1000*Dy0*sin(Cy*atan(By0*alpha - Ey*(By0*alpha - atan(By0*alpha))));
plot(alpha_deg, Fq, 'linewidth', 1.5), ylim([-4e3 4e3])
grid on, xlabel('\alpha, deg'), ylabel('F_{q}')
Bruno Luong
el 19 de Sept. de 2022
Yes, Padé fractional series is my loosly wording, rather use Padé approximant please.
help \sym\pade
Categorías
Más información sobre F Distribution en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!






