tags:

views:

125

answers:

1

I am using the FindRoot statement. My problem is that the results are only in symbolic form. How can I get mathematica to store results as a vector or list for easy use later.

g[r_]:=(A^r - 1)/(A^r - B^r);
func[r_]:= Piecewise[{{g[r],r<-.01 },{ g[r],r>.01} }];
roots = Table[0,{10}];
q= Table[pp,{pp,.01,0.1,0.01}];
Do[ roots[[i]]=FindRoot[func[r]== q[[i]],{r,0.9}];,{i,1,10}];    ********
Print[r/.roots];           *********** this prints out ok as a list


Pa2=Table[0,{10}];
myPa2=Table[0,{10}];
i/:IntegerQ[i]=True;    
r2=r;
h[r2_]:=(A^r2 - 1)/(A^r2 - B^r2);
funcOC[r2_]:= Piecewise[{{h[r2],r2<-.01 },{ h[r2],r2>.01} }];  
Do[ Pa2[[i]]=funcOC[r2[[i]]], {i,1,10} ];
Print[myPa2/.Pa2];      ****************symbolic notation is output
+1  A: 

To expand on Michael's question the code, as it currently stands, does not produce numerical values because the values of A and B have not been set.

If values are chosen for A and B FindRoot no longer returns a symbolic answer.

g[r_] := (A^r - 1)/(A^r - B^r);
A = .4; B = .5;
func[r_] := Piecewise[{{g[r], r < -.01}, {g[r], r > .01}}];
roots = Table[0, {10}];
q = Table[pp, {pp, .01, 0.1, 0.01}];
Do[roots[[i]] = FindRoot[func[r] == q[[i]], {r, 0.9}];, {i, 1, 10}];
Print[r /. roots];

{-201.021,-198.983,-196.97,-194.98,-186.987,-178.398,-170.282,-162.61,-155.352,-148.484}

For your second block of code I assume your problem is caused by r2[[i]] in:

Do[ Pa2[[i]]=funcOC[r2[[i]]], {i,1,10} ];

I think you meant:

Do[ Pa2[[i]]=funcOC[i], {i,1,10} ];

Did you mean to use the roots you found in your first block of code? If so you need to replace.

r2=r;

with

r2=r /. roots;
Davorak