<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <channel>
    <link>http://www.mathworks.es/matlabcentral/newsreader/view_thread/305581</link>
    <title>MATLAB Central Newsreader - Solve non-linear functions rapidly?</title>
    <description>Feed for thread: Solve non-linear functions rapidly?</description>
    <language>en-us</language>
    <copyright>&amp;copy;1994-2013 by MathWorks, Inc.</copyright>
    <webmaster>webmaster@mathworks.com</webmaster>
    <generator>MATLAB Central Newsreader</generator>
    <docs>http://blogs.law.harvard.edu/tech/rss</docs>
    <ttl>60</ttl>
    <image>
      <title>MathWorks</title>
      <url>http://www.mathworks.es/images/membrane_icon.gif</url>
    </image>
    <item>
      <pubDate>Sun, 03 Apr 2011 17:52:05 +0000</pubDate>
      <title>Solve non-linear functions rapidly?</title>
      <link>http://www.mathworks.es/matlabcentral/newsreader/view_thread/305581#829032</link>
      <author>Jani Korhonen</author>
      <description>Dear all,&lt;br&gt;
&lt;br&gt;
I want to solve this function C1 * x^2 - exp(C2 * x) = 0 in Matlab, in which C1 and C2 are constants. I know it is easy to use fsolve to solve it, e.g. x=fsolve((x)C1*x^2-exp(C2*x), 0). My question is that x is a matrix, and I want to solve this equation at each point, i.e. obtaining an individual x value at each point. C1 and C2 might be different at different points, but they can be obtained in advance.&lt;br&gt;
&lt;br&gt;
However, if I use a loop to find out the answer at each point, it takes a lot of time. But if I use the following: X = fsolve((X), C1*X^2-exp(C2*X), zeros(size(X, 1), size(X, 2)), where X is a matrix. Matlab says that x must be square. It seems the function was not treated at individual points. So, how can I solve this equation rapidly? Thank you very much.&lt;br&gt;
&lt;br&gt;
Best regards,&lt;br&gt;
&lt;br&gt;
Jani</description>
    </item>
    <item>
      <pubDate>Sun, 03 Apr 2011 18:13:26 +0000</pubDate>
      <title>Re: Solve non-linear functions rapidly?</title>
      <link>http://www.mathworks.es/matlabcentral/newsreader/view_thread/305581#829035</link>
      <author>Nasser M. Abbasi</author>
      <description>On 4/3/2011 10:52 AM, Jani Korhonen wrote:&lt;br&gt;
&amp;gt; Dear all,&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; I want to solve this function C1 * x^2 - exp(C2 * x) = 0 in Matlab, in which C1 and C2 are constants.&lt;br&gt;
&amp;gt;  I know it is easy to use fsolve to solve it, e.g. x=fsolve((x)C1*x^2-exp(C2*x), 0). My question is that x is&lt;br&gt;
&amp;gt;  a matrix, and I want to solve this equation at each point, i.e. obtaining an individual x value at each point.&lt;br&gt;
&amp;gt;  C1 and C2 might be different at different points, but they can be obtained in advance.&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; However, if I use a loop to find out the answer at each point, it takes a lot of time. But if&lt;br&gt;
&amp;gt;  I use the following: X = fsolve((X), C1*X^2-exp(C2*X), zeros(size(X, 1), size(X, 2)), where X is a&lt;br&gt;
&amp;gt;  matrix. Matlab says that x must be square. It seems the function was not treated at individual points.&lt;br&gt;
&amp;gt;  So, how can I solve this equation rapidly? Thank you very much.&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; Best regards,&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; Jani&lt;br&gt;
&lt;br&gt;
If I understand you right, this is what you want to do:&lt;br&gt;
&lt;br&gt;
Find the roots of f(x) near number of points in one call.&lt;br&gt;
&lt;br&gt;
Right?&lt;br&gt;
&lt;br&gt;
Then why not just list those points in an array, and pass&lt;br&gt;
that array to fsolve? Why do you need this matrix thing for?&lt;br&gt;
&lt;br&gt;
EDU&amp;gt;&amp;gt; points_to_find_roots_near = [1 2 3 4 5 6];&lt;br&gt;
EDU&amp;gt;&amp;gt; fsolve(@(x) sin(3*x),points_to_find_roots_near )&lt;br&gt;
&lt;br&gt;
ans =&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;1.0472    2.0944    3.1416    4.1888    5.2360    6.2832&lt;br&gt;
&lt;br&gt;
You might have to change the above to handle different C1, C2 in your&lt;br&gt;
equation, but I am here just talking about the need to supply&lt;br&gt;
the points.&lt;br&gt;
&lt;br&gt;
--Nasser</description>
    </item>
    <item>
      <pubDate>Sun, 03 Apr 2011 18:19:05 +0000</pubDate>
      <title>Re: Solve non-linear functions rapidly?</title>
      <link>http://www.mathworks.es/matlabcentral/newsreader/view_thread/305581#829036</link>
      <author>Roger Stafford</author>
      <description>"Jani Korhonen" &amp;lt;eagle_nokia@hotmail.com&amp;gt; wrote in message &amp;lt;inac45$6lr$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; Dear all,&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; I want to solve this function C1 * x^2 - exp(C2 * x) = 0 in Matlab, in which C1 and C2 are constants. I know it is easy to use fsolve to solve it, e.g. x=fsolve((x)C1*x^2-exp(C2*x), 0). My question is that x is a matrix, and I want to solve this equation at each point, i.e. obtaining an individual x value at each point. C1 and C2 might be different at different points, but they can be obtained in advance.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; However, if I use a loop to find out the answer at each point, it takes a lot of time. But if I use the following: X = fsolve((X), C1*X^2-exp(C2*X), zeros(size(X, 1), size(X, 2)), where X is a matrix. Matlab says that x must be square. It seems the function was not treated at individual points. So, how can I solve this equation rapidly? Thank you very much.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Best regards,&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Jani&lt;br&gt;
- - - - - - - - - -&lt;br&gt;
&amp;nbsp;&amp;nbsp;Substituting w = -C2/2*x puts your equation in the form of Lambert's W equation.  Solutions for that can be obtained from the 'lambertw' function in the Symbolic Toolbox which accepts numeric matrices.  That might be faster than using 'fsolve'.&lt;br&gt;
&lt;br&gt;
Roger Stafford</description>
    </item>
    <item>
      <pubDate>Sun, 03 Apr 2011 18:21:04 +0000</pubDate>
      <title>Re: Solve non-linear functions rapidly?</title>
      <link>http://www.mathworks.es/matlabcentral/newsreader/view_thread/305581#829037</link>
      <author>Jani Korhonen</author>
      <description>Dear Nasser,&lt;br&gt;
&lt;br&gt;
Thanks a lot for your help. But I don't think this is what I hope. Actually my question is very simple. I have a matrix X, and I want to find the root of each element in the matrix, i.e. C1*x(i,j)^2-exp(C2*x(i,j))=0. But I don't want to use loop.&lt;br&gt;
&lt;br&gt;
BTW, if I want to find out the optimal POSITIVE root for each element, how can I do? Thank you very much.&lt;br&gt;
&lt;br&gt;
Best regards,&lt;br&gt;
&lt;br&gt;
Jani&lt;br&gt;
&lt;br&gt;
"Nasser M. Abbasi" &amp;lt;nma@12000.org&amp;gt; wrote in message &amp;lt;inadc3$r5u$1@speranza.aioe.org&amp;gt;...&lt;br&gt;
&amp;gt; On 4/3/2011 10:52 AM, Jani Korhonen wrote:&lt;br&gt;
&amp;gt; &amp;gt; Dear all,&lt;br&gt;
&amp;gt; &amp;gt;&lt;br&gt;
&amp;gt; &amp;gt; I want to solve this function C1 * x^2 - exp(C2 * x) = 0 in Matlab, in which C1 and C2 are constants.&lt;br&gt;
&amp;gt; &amp;gt;  I know it is easy to use fsolve to solve it, e.g. x=fsolve((x)C1*x^2-exp(C2*x), 0). My question is that x is&lt;br&gt;
&amp;gt; &amp;gt;  a matrix, and I want to solve this equation at each point, i.e. obtaining an individual x value at each point.&lt;br&gt;
&amp;gt; &amp;gt;  C1 and C2 might be different at different points, but they can be obtained in advance.&lt;br&gt;
&amp;gt; &amp;gt;&lt;br&gt;
&amp;gt; &amp;gt; However, if I use a loop to find out the answer at each point, it takes a lot of time. But if&lt;br&gt;
&amp;gt; &amp;gt;  I use the following: X = fsolve((X), C1*X^2-exp(C2*X), zeros(size(X, 1), size(X, 2)), where X is a&lt;br&gt;
&amp;gt; &amp;gt;  matrix. Matlab says that x must be square. It seems the function was not treated at individual points.&lt;br&gt;
&amp;gt; &amp;gt;  So, how can I solve this equation rapidly? Thank you very much.&lt;br&gt;
&amp;gt; &amp;gt;&lt;br&gt;
&amp;gt; &amp;gt; Best regards,&lt;br&gt;
&amp;gt; &amp;gt;&lt;br&gt;
&amp;gt; &amp;gt; Jani&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; If I understand you right, this is what you want to do:&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Find the roots of f(x) near number of points in one call.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Right?&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Then why not just list those points in an array, and pass&lt;br&gt;
&amp;gt; that array to fsolve? Why do you need this matrix thing for?&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; EDU&amp;gt;&amp;gt; points_to_find_roots_near = [1 2 3 4 5 6];&lt;br&gt;
&amp;gt; EDU&amp;gt;&amp;gt; fsolve(@(x) sin(3*x),points_to_find_roots_near )&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; ans =&lt;br&gt;
&amp;gt;      1.0472    2.0944    3.1416    4.1888    5.2360    6.2832&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; You might have to change the above to handle different C1, C2 in your&lt;br&gt;
&amp;gt; equation, but I am here just talking about the need to supply&lt;br&gt;
&amp;gt; the points.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; --Nasser&lt;br&gt;
&amp;gt; </description>
    </item>
    <item>
      <pubDate>Sun, 03 Apr 2011 18:33:04 +0000</pubDate>
      <title>Re: Solve non-linear functions rapidly?</title>
      <link>http://www.mathworks.es/matlabcentral/newsreader/view_thread/305581#829038</link>
      <author>Jani Korhonen</author>
      <description>Great, Roger, thanks a lot. Your suggestion is wonderful.&lt;br&gt;
&lt;br&gt;
"Roger Stafford" wrote in message &amp;lt;inadmp$8u$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; "Jani Korhonen" &amp;lt;eagle_nokia@hotmail.com&amp;gt; wrote in message &amp;lt;inac45$6lr$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; &amp;gt; Dear all,&lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; I want to solve this function C1 * x^2 - exp(C2 * x) = 0 in Matlab, in which C1 and C2 are constants. I know it is easy to use fsolve to solve it, e.g. x=fsolve((x)C1*x^2-exp(C2*x), 0). My question is that x is a matrix, and I want to solve this equation at each point, i.e. obtaining an individual x value at each point. C1 and C2 might be different at different points, but they can be obtained in advance.&lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; However, if I use a loop to find out the answer at each point, it takes a lot of time. But if I use the following: X = fsolve((X), C1*X^2-exp(C2*X), zeros(size(X, 1), size(X, 2)), where X is a matrix. Matlab says that x must be square. It seems the function was not treated at individual points. So, how can I solve this equation rapidly? Thank you very much.&lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; Best regards,&lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; Jani&lt;br&gt;
&amp;gt; - - - - - - - - - -&lt;br&gt;
&amp;gt;   Substituting w = -C2/2*x puts your equation in the form of Lambert's W equation.  Solutions for that can be obtained from the 'lambertw' function in the Symbolic Toolbox which accepts numeric matrices.  That might be faster than using 'fsolve'.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Roger Stafford</description>
    </item>
  </channel>
</rss>
