octave - How do I solve a function for x in Matlab? -
I have defined this function:
% entered in two vectors Enter data, mass and duration mass = 0: 200: 1200; Period = [0.404841 0.444772 0.486921 0.522002 0.558513 0.589238 0.622 9 42]; Calculate a line of best fit for data using% Polyfit () P = polyfit (mass, duration, 1); Fit = @ (X) P (1). * X + p (2);
Now I want to solve f (x) = 440086, but there can be no way to do this. I know that I can work it easily with my hand, but I have to know how to do this in the future.
If you have a linear equation such as A * x + B = 0
If you want to solve, you can easily solve MATLAB as follows:
p = [0.2 0.5]; ConstValue = 0.440086; A = p (1); B = constValue-p (2); Soln = a \ b;
If you want to solve a non-linear system of equations, you can use fsolve
as the following (here I am showing I use it above the linear equation):
myFunSO = @ (x) 0.2 * x + 0.5-0.440086; % Here are the initial estimates that you are solving F (x) -0.440086 = 0x = fsolve (myFunSO, 0.5)% 0.5.
Both methods should give you the same solution.
Comments
Post a Comment