Hello everyone, I need some help here! I have a very complicated function of x. How can I find its roots? Thank you in advance!

 채택된 답변

Azzi Abdelmalek
Azzi Abdelmalek 2016년 6월 25일

0 개 추천

댓글 수: 1

Goldy
Goldy 2016년 6월 25일
편집: Goldy 2016년 6월 25일
Thank you very much. I'll tell you if this works!

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

추가 답변 (1개)

John D'Errico
John D'Errico 2016년 6월 25일

1 개 추천

Use fzero. Or solve. Or roots. Or vpasolve. Or fsolve. ...
Much depends on the function. How many variables? Is it in symbolic form? Are you looking for an analytical solution? All roots? (a nasty problem.)

댓글 수: 2

The function F is very complicated that's why I am so confused. It has 4 variables: x , y , z and Z. z = f(x) So, F = g(x,y,f(x),Z). I use y and Z in 2 for loops:
for y=5:20
for Z=1:10
% here I am doing some calculations that lead to the function F and then I want its roots
end
end
That it uses loops is not relevant. Put a function header in front of it, so that you can evaluate the thing as a function of a vector of length 3.
Why do I say 3? Because you have ONLY 3 variables (unknowns) NOT 4.
z may be a variable as you have written it, but it is NOT an independent unknown.
So you will have a function, perhaps called F, that takes a single vector. That vector must be of length 3. Inside the function, you will extract x,y,Z. Then create z from f(x), and evaluate your messy function in those loops.
The problem you will find is that NO rootfinder, including solve, vpasolve, fzero, roots, vpasolve, will work! In fact, this would be your next anguished question, "Why does my favorite root finder not work here?"
Ok, so why do I say that? Assuming that your messy relation here is a continuous function of the input unknowns (x,y,Z), then there will be generally infinitely many solutions if there are any solutions.
You can think of this as a contour plotting problem, with three dimensions. A contour plot (in two dimensions, can be viewed as finding the set of values for which some function w(u,v)==0, or any other fixed constant. In fact, contour plotters are usually used to solve that problem for various values of the fixed constants. This is called a level surface problem. Here, you have the same thing, but as a function of THREE input variables. So effectively, the general "solution" to your problem will look like a surface in three dimensions, what I might call a 2-manifold, embedded in the three dimensional space (x,y,Z). For example, the surface of a sphere would be one such case.
Ok, so how do you solve THAT problem? The simplest solution is to use a tool like isosurface.
You will need to compute the value of F at EVERY point in a 3-dimensional grid on the variables x,y,Z. So, use the function ndgrid to create all combinations of those variables. Then evaluate your function at EVERY combination of values, and finally call isosurface, like this:
isosurface(x,y,Z,values,0)

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

카테고리

도움말 센터File Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

질문:

2016년 6월 25일

댓글:

2016년 6월 25일

Community Treasure Hunt

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

Start Hunting!

Translated by