0

I've been looking around but I can't seem to figure out how I should use fsolve to solve my system of nonlinear equations.

so I have a function k, and I know that I want .01 as the starting value (required input for fsolve I believe). I also know that k(1000) =12 Lastly, I have a formula for k,

    k(N) = (1/(k(N).^.5 + .9*k(N) -k(N+1))) - ((.94 * .5 *k(N+1)^(1-.5) + .9)/(k(N+1)^.5 + 
   .9*k(N+1) - k(N+2)))

with N 1:1000. I figured I could just say fsolve(k(N), .01), but with the formula in place of k(N) (or is defining k(N) in a separate function necessary?), but I exceed the dimensions of N and also have issues with dimensions matching since there is N, N+1, and N+2 in the equation.

I think my issue may be stemming from the fact that I have defined vector valued functions where in reality I want them to be single valued, from 1:1000,but I don't know how to represent this in matlab (obviously I can't type in 1000 equations).

Any ideas, suggestions, or comments?

majmun
  • 131
  • 9
  • But what value are you trying to solve for? `N` is an input and there are no other unknowns in your equation. You know `k(0)` is `0.01` and from there you can calculate `k(1)` by just rearranging your equation and then keep substituting values in iteratively to find `k(N)`... – Dan Oct 16 '15 at 10:31
  • Oh I see there is a `k(N+2)` term, I think that implies that you'll need to adjacent starting values... i.e. you must know `k(0)` and `k(1)` or `k(1000)` and `k(1001)`... – Dan Oct 16 '15 at 10:32
  • I have been told that fsolve is what I can use to solve the system when I know k(0) and k(1000), but I do not know how. It is also possible, although not too likely, that I was told wrong. – majmun Oct 16 '15 at 10:39
  • I suppose if you parameter that adjust is `k(1)` and your target is to make `k(1000)` be `12` then you could solve it with `fsolve`... – Dan Oct 16 '15 at 10:55
  • It is true that the target is to make k(1000) be 12. – majmun Oct 16 '15 at 11:01
  • That sounds correct, I suggest you create a toy example of this problem where the target is something like `k(5)` = whatever and also simplify the formula for `k(N)` as well and try solve that. – Dan Oct 16 '15 at 11:17
  • Are you sure you have N-1 equations in N-1 unknowns? Your unknowns would be k(1)-->k(N-1) but you'll have equations only from s=1 to s=N-2 if k(N+1) is not definite – BillBokeey Oct 16 '15 at 12:44
  • Or is your question : Given an initial value k(1) and the value k(N), what's the vector [k(2),...,k(N-1)] that verifies the constraints? (in that case i got some working code) – BillBokeey Oct 16 '15 at 12:49
  • Moreover : Can you rewrite the equation you have for k? It's pretty unclear at the moment (Notably the ,.01 part at the end) – BillBokeey Oct 16 '15 at 13:15
  • Yes, it is exactly what you said: given an initial value for k(1), and an ending value k(N), how can I find the vector [k(2,...,k(N-1)] that verify the constraints. However, the k(2),...k(N-1) needs to be of the form specified for k(N) above. and I will clean up the equation. My apologies. – majmun Oct 16 '15 at 14:38
  • Okay, i'll post some working code on monday – BillBokeey Oct 17 '15 at 12:07

0 Answers0