Nonlinear Equation Model and Solution Examples



1. Gas equation model

Example 1.
The pressure P, volume V, and temperature T of 1 mole of an ideal gas satisfy the relationship PV=RT, where the constant R=0.08205 (l atm/K mol), and this relationship needs to be corrected as
(P + a V c \ frac{a}{ V^c}Vca) (V - b) = RT
a,b,c are constants determined by the given gas. Now it is known that a=12.87, b=0.1142, c=2, find the volume V of the gas at P=2(atm), T=313(K).

Analysis
First, the basic mathematical model of this question can be obtained according to the numerical values ​​and formula equations given in the question. The equation is a nonlinear equation system. As mentioned in the previous blog, the fzero function can be used to solve the equation. Of course, before solving the equation , the approximate image of the equation can be drawn, and the code for determining the approximate range of the root
is as follows:

%气体的一些常数
a=12.87;b=0.1142;c=2;
R=0.08205;
%压强和温度
P=2;T=313;
%理想气体方程:P*V=R*T;
%实际气体方程:
%f(V) = (p+a / V ^ c) * (V - b) - R * T 
V0 = R * T / P;
f=@(V) (P + a ./  V .^ c) .* (V - b) - R * T;
fplot(f, [0.1, 15]);
V = fzero(f, V0)

The image can be obtained:
Gas Equation Image
It can be seen from the image that there are three solutions to the equation, but we only seek the roots near the approximate solution V0 = R * T / P, and the result is:

V =
   12.4426

2. Mortgage repayment issues

Example 2. (The interest rate of the house purchase loan)
The following is a real estate advertisement:
insert image description here
It is not difficult to calculate that you have borrowed a total of 252,000 from the bank, and you
have to repay a total of 516,960 in 30 years.
What is the annual interest rate of the loan in this case?

Analysis
Let xk x_kxkis the amount owed at the end of the kth month, a is the monthly repayment amount, and r is the monthly interest rate.
xk x_kxk = (1+ r) x k − 1 x_{k-1} xk1 - a
= (1+r)2 x k − 2 x_{k-2} xk2 – (1+r) a – a
=……
= (1+r)k x 0 x_{0} x0 – a[1+(1+r)+……+(1+r)k-1]
= (1+r)k x 0 x_{0} x0 – a ( 1 + r ) k − 1 r \cfrac{(1+r)^k-1}{r} r(1+r)k1
According to the meaning of the question, x 360 x_{360}x360= 0, so the equation can be listed and the image can be drawn to solve it

code show as below:

%房贷年利率问题
%设 xk 表示(从现在开始过了k个月后的)欠款(现在的时间为,k=0%设每个月还款a (单位:元),月利息为 r,则 x0 = 25.2
%x1 = x0(1 + r) - a (第一个月月初)
%x2 = x1(1 + r) - a (第二个月月初)
%……
%x360 = x359*1 + r)- a(第360个月月初还 a)
%x360 = 0
x0=25.2;
a=0.1436;
f=@(r) x0*(1+r).^360 - a*( (1+r).^360 - 1 ) ./ r ;
r0=0.001;
r=fzero(f,r0);
year_interest = r*12

Of course, we found that, given the recursive relation, we can write a recursive function to calculate x 360 x_{360}x360mathematical relation

Find the recursive function code:

function y = loan(x0, a, r, k)
%功能:已知初始欠款数x0,每个月还款数a,月利息r,求k个月以后的欠款y
i=0;
y=x0;
for i=1:k
    y=y*(1+r)-a;
end
end
%function y = loan(x0, a, r, k)
%功能:已知初始欠款数x0,每个月还款数a,月利息r
%求k个月以后的欠款y
x0=25.2;
a=0.1436;
%解方程f(r) = loan(x0, a, r, 360) = 0
f=@(r)loan(x0, a, r, 360);
r0=0.001;
r=fzero(f,r0);
year_interest = r*12

This method can also find the solution of the equation, but it should be noted that when the amount of data is huge, the recursive calculation will take up a lot of space and time. In this case, it is not as convenient as the derived relational formula. At the same time, pay attention to whether the iteration relation converges when iterating linearly.
The result of this question is:

year_interest =
    0.0553

3. The problem of oblique throwing

It is known that a shell is fired obliquely, with an initial velocity of 200 meters per second, and when it hits a target at a horizontal distance of 360 meters and a vertical distance of 160 meters, what is the launch angle when air resistance is ignored?

This is a simple high school physics problem, let's build a mathematical model to solve it

Analyze
our orthogonal decomposition of the trajectory of the projectile, set the launch angle as alpha, use x(t), y(t) to represent the position of the projectile at time t, and the initial velocity is v0, since the projectile is only subject to gravity when it is launched, we can list Equations for both horizontal and vertical directions:
v 0 v_0v0*cos(alpha) *t = 360
v 0 v_0 v0*sin(alpha) *t - 1 2 \frac 12 21gt 2 = 160
Then, we can use nonlinear equations to solve

code show as below:

%炮弹发射为斜抛运动,已知初速度为200米每秒,
%问击中水平距离360米时,垂直距离160m的目标,问当忽略空气阻力时发射角多大
%设发射角为alpha,用x(t),y(t)表示 t时刻炮弹的位置,初始速度为v0,由于炮弹发射出去只受到重力
%X=[alpha, T]
g=9.8;
fun = @(X) [200*cos(X(1)) * X(2)- 360
    200*sin(X(1)) * X(2) - 1 / 2*g*X(2)^2 - 160];
X0=[pi/6, 5];  %估计初值
X=fsolve(fun,X0)
alpha = X(1) / pi *180 %弧度制转换角度值

Of course, we can also dynamically observe the trajectory of the shell

%炮弹运动轨迹
g=9.8;
f=@(a) 180*sin(2*a)-g/2*1.8^2 - 160*cos(a)^2;
a=fzero(f, pi/6);
figure
axis([0,360,0,160])
hold on
for t=0:0.001:2.012
    x=200*cos(a)*t;
    y=200*sin(a)*t - 1/2*g*t^2;
    plot(x,y,'r.')
    pause(0.005)
end

The result is:

X =
    0.4633    2.0121
alpha =
   26.5444

Summarize

The general process of mathematical modeling can basically be summarized as (personal understanding),
sorting out relational expressions - writing mathematical equations or equations - drawing correlation function curves to analyze problems - solving equations to get the solution of the problem - back band test error

Guess you like

Origin blog.csdn.net/qq_49288154/article/details/122303239