如何在Matlab中解决x的函数?

时间:2014-02-18 00:44:00

标签: matlab octave

我定义了这个函数:

% Enter the data that was recorded into two vectors, mass and period
mass = 0 : 200 : 1200;
period = [0.404841 0.444772 0.486921 0.522002 0.558513 0.589238 0.622942];

% Calculate a line of best fit for the data using polyfit()
p = polyfit(mass, period, 1);
fit=@(x) p(1).*x + p(2);

现在我想解决f(x)= .440086,但找不到办法做到这一点。我知道我可以轻松地手工完成它,但我想知道将来如何做到这一点。

1 个答案:

答案 0 :(得分:4)

如果要求解A*x+B=0等线性方程式,可以在MATLAB中轻松求解如下:

p=[0.2 0.5];
constValue=0.440086;
A=p(1);
B=constValue-p(2);
soln=A\B;

如果你想解决非线性方程组,你可以使用fsolve如下(这里我将展示如何用它来解决上面的线性方程):

myFunSO=@(x)0.2*x+0.5-0.440086;  %here you are solving f(x)-0.440086=0
x=fsolve(myFunSO,0.5)  %0.5 is the initial guess.

两种方法都应该为您提供相同的解决方案。

相关问题