|Feb19-08, 01:59 PM||#1|
MATLAB numerical evaluation doubt
Hi! I need help from someone that knows something about numerical methods in MATLAB. Specifically, fsolve.
So, I have an equation L = K(x) - F(x,y). Given the values of L and y, I need to determine the value of x numerically.
So, here's what I've done:
G(x) = L- K(x) + F(x,y)
in the function m-file
function [G] = g(x,y,L)
I then need to evaluate G(x) numerically to find the values of x at which G(x) becomes 0. Thats my understanding of numerical determination.
So I use the fsolve command in Matlab this way
[x, fval] = fsolve(@g, x, options);
But the problem is that I need to pass multiple values of y, L and some initial estimate of x (that apparently fsolve requires) to find different values of x for different values of y. Matlab doesnt accept this. i.e. ideally I'd like to do something like
[x, fval] = fsolve(@g(x,y,L), x, options);
where I can pass multiple values of y and L (array or for-loop) to find the values of x.
Can I do this? or do I need to declare Global variables and access y and L in function g that way?
Also, if I've no idea of what x looks like, how do I estimate an initial value?
Would appreciate your contributions to resolving this.
|Feb19-08, 02:30 PM||#2|
There are various aways to do this.
The simplest way is to use an anonymous function (look in the help-files, as far as I remember fsolve is used to illustrate how they are used). Or, alternatively, use nested functions (where you have more than one function per file, and access to all the variables). Personally I prefer the former.
About finding a first guess: Try plotting the function for different values for L and y; the inital guess only needs to be in the "neighborhood" in order for fsolve to be efficient.
|Feb20-08, 02:37 PM||#3|
I created and used the anonymous function and it worked out fine.
g = @(x) L-K(x)+F(x,y)
[x] = fsolve(g, x, options)
It worked fine except when Matlab threw some warnings at some of the iterations:
Warning, unable to determine if -4503599627370496*pi*(1+2*_Z13)/(-4503599627370496*pi+1746276232035673*i) is between 0 and 1; try to use assumptions or set option _EnvAllSolutions to true
Setting that option to true didn't help.
Is this an error with the way I've used fsolve? I'm using the int() command for integration in one of the functions and using syms too. The symbolic variables can sometimes cause fsolve to throw errors like these, but I've tried resolving it using double(int(...)). It worked better than the first time (meaning more iterations went through), but sort of just collapsed later.
|Similar Threads for: MATLAB numerical evaluation doubt|
|Evaluation of Numerical series by Fourier series||Calculus & Beyond Homework||7|
|Matlab Numerical Integration||Math & Science Software||3|
|MATLAB numerical evaluation||Math & Science Software||0|
|numerical analysis (composite numerical integration)||Engineering, Comp Sci, & Technology Homework||9|
|Integral evaluation - analytical vs. numerical||General Math||11|