牛顿法

时间:2017-10-05 12:55:54

标签: matlab numerical-methods

我试图使用牛顿方法(对任何其他方法开放)找出方程约束的根。方程约束取决于具有一个未知项的二次方程的根。方程描述(二次和约束)如下所示。假设二次方程的根为p1p2

x^2 + x*(c1*unknown/2 + C1*c2)/(c1*c2*c3*unknown/2) + 1/(c1*c2*c3*u/2) = 0

有约束

(1/(p2-p1))*(exp(-0.3*p2) - 1)*(c1*c2 - p2) - (exp(-0.3*p1) - 1)*(c1*c2 - p1) - 0.04 = 0

我想知道如果牛顿方法不这样做,是否还有其他近似方法可以解决这个问题。

Matlab代码

p0=10*10^6;
Cc=0.65*10^-6;Rp=100*10^3;Cp=55*10^-9; z1=1/(Cp*Rp);
N = 100;error = 0.02;  
syms 'x'
a = 1;
b = ((Cc*(x/2+Rp))/(Cc*Cp*Rp*x/2));
c = 1/(Cc*Cp*Rp*x/2);
poles1 = (-b + sqrt(b^2 - 4*a*c))/(2*a);
poles2 = (-b - sqrt(b^2 - 4*a*c))/(2*a);

p1_subterm = (exp(-0.3*poles1) - 1)*(z1 - poles1);
p2_subterm = (exp(-0.3*poles2) - 1)*(z1- poles2);
f(x) = (1/(poles2 - poles1))*p2_subterm - p2_subterm - 0.04;          
df = diff(f);  
while i <= N
 p = p0-(f(p0)/df(p0)) 
if (abs(p - p0)/abs(p)) < error 
fprintf('Solution is %f \n', double(p))
return
end
i = i + 1;
p0 = p;
end
fprintf('Solution did not converge within %d iterations \n', N)

1 个答案:

答案 0 :(得分:-1)

我认为1/(poles2-poles1)的代码与上面列出的等式相对应:在MATLAB代码中exp((...)poles2)exp((...)poles1)1/(c1*c2) - poles1两个术语相乘而且你有c1*c2 - poles1而不是poles1

我没有查看poles2c1*c2*c3*unknown条款,因为我发现10组括号令人生畏。它建议通过将每个方程式分解为更短,更清晰的行来使您的代码更具可读性。

注意我们可以将二次乘以(c1*c2*c3*unknown)*x^2 + x*2*(c1*unknown/2 + C1*c2) + 2 = 0

poles

然后您可以将f% Here unknown is x syms 'x' a = c1*c2*c3*x; b = c1*x + 2*c1*c2; c = 2; poles1 = (-b + sqrt(b^2 - 4*a*c))/(2*a); poles2 = (-b - sqrt(b^2 - 4*a*c))/(2*a); p1_subterm = (exp(-0.3*poles1) - 1)*(c1*c2 - poles1); p2_subterm = (exp(-0.3*poles2) - 1)*(c1*c2 - poles2); f(x) = (1/(poles2 - poles1))*p2_subterm - p2_subterm - 0.04; 代码编写为

public static String formatTime(long millis) {
    SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss.SSS");

    String strDate = sdf.format(millis - 3600000);
    return strDate;
}