使用倍频程求解方程 [英] solving equation using octave
问题描述
我想解决一个简单的方程式
I have a simple equation I'm trying to solve
num1=-2
num2=-3
x+num2=num1
x+-3=-2
x=1
如何以八度为单位进行此操作.在matlab中,我可以执行 y = solve('x-3 = -2'),但这在我正在使用的版本的 octave 3.8.1中不起作用 >.如何获得八度来求解这些类型的方程式?
How can I do this in octave. In matlab I can do y = solve('x-3 = -2') but this doesn't work in octave 3.8.1 which is the version I'm using. How can I get octave to solve these types of equations?
我对解决方案的数值很感兴趣.
I'm interested in the numeric value for a solution.
推荐答案
我假设您问题中的方程式是一个示例.如果您对数值解法感兴趣,通常不需要使用符号数学.在八度(或Matlab)中,您可以使用 fzero
查找用单变量自由变量表示的非线性方程的实根/零.对于简单的线性示例,使用匿名函数来代表你的方程式:
I'm assuming that the equation in your question is an example. If you're interested in a numeric solution, there is often no need to use symbolic math. In Octave (or Matlab), you can can use fzero
to find a real root/zero of a nonlinear equation in terms of a single-variable free variable. For your simple linear example, using an anonymous function to represent your equation:
num1 = -2;
num2 = -3;
f = @(x)x+num2-num1;
x0 = 0; % Initial guess for x
x = fzero(f,x0)
如果方程式具有多个根/零,则需要在每个零附近尝试不同的初始猜测,以找到确切的值.
If an equation has multiple roots/zeros you'll need to try different initial guesses in the vicinity of each zero to find the exact value.
Octave还具有Matlab的 fsolve
求解多变量非线性方程组.如果您的方程是线性的(例如A*x = b
),则应查看 linsolve
.
Octave also has a version of Matlab's fsolve
to solve systems of nonlinear equations in multiple variables. If your equations are linear (e.g., A*x = b
), you should look at linsolve
.
这篇关于使用倍频程求解方程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!