http://www.mathworks.com/matlabcentral/newsreader/view_thread/325375
MATLAB Central Newsreader  how can i solve inline system of equations using fsolve()
Feed for thread: how can i solve inline system of equations using fsolve()
enus
©19942014 by MathWorks, Inc.
webmaster@mathworks.com
MATLAB Central Newsreader
http://blogs.law.harvard.edu/tech/rss
60
MathWorks
http://www.mathworks.com/images/membrane_icon.gif

Sun, 23 Dec 2012 13:28:07 +0000
how can i solve inline system of equations using fsolve()
http://www.mathworks.com/matlabcentral/newsreader/view_thread/325375#894199
Tian
I am a programmer but am new to the syntax of matlab. <br>
I wonder how I could fsolve a system of nonlinear functions. Here is my code:<br>
<br>
x = X(i1)<br>
y = Y(i1)<br>
a = (sqrt(3)1)/(2*sqrt(3))<br>
b = (sqrt(3)+1)/(2*sqrt(3))<br>
c = (sqrt(3)2)/(4*sqrt(3))<br>
d = (sqrt(3)+2)/(4*sqrt(3))<br>
<br>
G = @(k)('[k(:,1)  (4*(x + a*h) + y + h/2*k(:,1) + c * h * k(:,2)  1)^(0.5); k(:,2)  (4*(x + b*h) + y + d*h*k(:,1) + h/4*k(:,2) 1)^(0.5)]')<br>
<br>
[k, fval] = fsolve(G, [0.0,0.0])<br>
<br>
<br>
Basically, I want to use the two equations to solve for k with k1 and k2....<br>
But I received the following error message:<br>
<br>
Error using fsolve (line 280)<br>
FSOLVE requires all values returned by user functions to be of<br>
data type double.<br>
Error in rk4 (line 26)<br>
[k, fval] = fsolve(G, [0.0,0.0])<br>
<br>
I don't know what's wrong. Thx.

Sun, 23 Dec 2012 15:24:05 +0000
Re: how can i solve inline system of equations using fsolve()
http://www.mathworks.com/matlabcentral/newsreader/view_thread/325375#894205
Nasser M. Abbasi
On 12/23/2012 7:28 AM, Tian wrote:<br>
> I am a programmer but am new to the syntax of matlab.<br>
> I wonder how I could fsolve a system of nonlinear functions. Here is my code:<br>
><br>
<br>
I think fsolve wants numbers, not symbols. Try with actual numbers.<br>
<br>
also your code posted is not complete.<br>
<br>
<br>
> x = X(i1)<br>
> y = Y(i1)<br>
> a = (sqrt(3)1)/(2*sqrt(3))<br>
> b = (sqrt(3)+1)/(2*sqrt(3))<br>
> c = (sqrt(3)2)/(4*sqrt(3))<br>
> d = (sqrt(3)+2)/(4*sqrt(3))<br>
><br>
> G = @(k)('[k(:,1)  (4*(x + a*h) + y + h/2*k(:,1) + c * h * k(:,2)  1)^(0.5); k(:,2)  (4*(x + b*h) + y + d*h*k(:,1) + h/4*k(:,2) 1)^(0.5)]')<br>
><br>
> [k, fval] = fsolve(G, [0.0,0.0])<br>
><br>
><br>
> Basically, I want to use the two equations to solve for k with k1 and k2....<br>
> But I received the following error message:<br>
><br>
> Error using fsolve (line 280)<br>
> FSOLVE requires all values returned by user functions to be of<br>
> data type double.<br>
> Error in rk4 (line 26)<br>
> [k, fval] = fsolve(G, [0.0,0.0])<br>
><br>
> I don't know what's wrong. Thx.<br>
>

Sun, 23 Dec 2012 19:13:08 +0000
Re: how can i solve inline system of equations using fsolve()
http://www.mathworks.com/matlabcentral/newsreader/view_thread/325375#894213
Roger Stafford
"Tian " <tc28@cs.brown.edu> wrote in message <kb70t7$pgj$1@newscl01ah.mathworks.com>...<br>
> G = @(k)('[k(:,1)  (4*(x + a*h) + y + h/2*k(:,1) + c * h * k(:,2)  1)^(0.5); k(:,2)  (4*(x + b*h) + y + d*h*k(:,1) + h/4*k(:,2) 1)^(0.5)]')<br>
> <br>
> [k, fval] = fsolve(G, [0.0,0.0])<br>
         <br>
Your equations can fairly easily be reduced by hand to finding the four roots of a certain quartic equation for which you could use matlab's 'roots' function. Or you could use matlab's 'solve' to do that reducing for you. Perhaps 'solve' might even get the numerical solution for you (provided you furnish the values of x, y, and h.) That would avoid making possibly inappropriate initial estimates for 'fsolve'.<br>
<br>
Roger Stafford