fsolve on polynominal function

조회 수: 21 (최근 30일)
Aleksander Vae Haaland
Aleksander Vae Haaland 2019년 9월 27일
댓글: Aleksander Vae Haaland 2019년 9월 27일
Hey!
I need to use fsolve to calculate y=1 in a non linear function, y = ax^2 + bx + c .
x, a, b and c is matrix.
I don't understand the documentation around fsolve and need this to work by the end of the day..
If anybody can help out, I would be so happy!
The code I have been trying out, is below. Ask if there is anything I can help with!
x0 = [0,0];
solveTest = fsolve(myFun(x, a, b, c), x0);
function y = myFun(x, a, b, c)
y = a.*x.^2 + b.*x + c;
y(x) = 1;
end

답변 (1개)

Guillaume
Guillaume 2019년 9월 27일
Solving is the same as solving , which is easily solved with roots:
roots([a, b, c-1])
your myfun doesn't make much sense:
y = a.*x.^2 + b.*x + c; %assuming a,b,c and x are scalar results in y being a scalar value
y(x) = 1; %set the element of array y (which has just one element) at index x (which may not even be integer) to 1
fsolve solves for not for . Again, the latter is easily rewrittent as but using fsolve, an iterative process that may return an approximation of the roots is a complete waste of time when there's a function for getting the roots of polynomial.
  댓글 수: 1
Aleksander Vae Haaland
Aleksander Vae Haaland 2019년 9월 27일
Looked good. Remembered now that a, b and c is matrixes. That kinda complicates things.. Is there a way to rewrite it?

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Linear Algebra에 대해 자세히 알아보기

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by