Message Boards Message Boards

0
|
6810 Views
|
4 Replies
|
1 Total Likes
View groups...
Share
Share this post:

Change the variable in the function? (SOLVED)

Posted 8 years ago

part of a bigger code, I am trying to replace the variable in the function by using:

vars = {x, y, z, r, p, l};
varlims = {{1, 2}, {3, 4}, {5, 6}, {7, 8}, {9, 10}, {11, 12}};
poi = {x, y};
svars = {z, r, p, l};
poi[[1]]
u = z Sin[\[Pi] x] + z  Cos[\[Pi] y] + y^6 Cos[2 \[Pi] y];
u /. poi[[1]] -> v1

poi[[1]] is x there I see it but why can't I replace it by v1? I think ./ -> looking for poi[[1]] as a string how can make it to represent x?

POSTED BY: Erdem Uguz
4 Replies
Posted 8 years ago

Kind of yes, I found that I need to rename the u function as

u1 = u /. poi[[1]] -> v1;
u2 = u1 /. poi[[2]] -> v2;

and plot it

psl = Plot3D[u2, {v1, lv1, rv1}, {v2, lv2, rv2}, 
  PerformanceGoal -> "Quality", Mesh -> None, 
  ColorFunction -> Function[{x, y, z}, Hue[z]], ImageSize -> Medium]
POSTED BY: Updating Name

Hello, if I run your code I get, as expected

z*Cos[Pi*y] + 
 y^6*Cos[2*Pi*y] + 
 z*Sin[Pi*v1]

So probably there is some assignement to v1 in your code before.

POSTED BY: Rolf Mertig
Posted 8 years ago

You are right. When I run in a new .nb file it was fine. But I don't understand why this is not working in the following format.

Manipulate[
 DynamicModule[{u = 
    z Sin[\[Pi] x] + z  Cos[\[Pi] y] + y^6 Cos[2 \[Pi] y], 
   vars = {x, y, z}, varlims = {{-3, 3}, {-3, 3}, {5, 6}}, 
   poi = {x, y}, svars = {z}},
  Column[{Style["Ploter", "Function"] ,
    Row[{"Function  ", InputField[Dynamic[u]]}, Spacer[20]],
    Row[{"Variables ", InputField[Dynamic[vars]]}],
    Row[{"Variable limits ", InputField[Dynamic[varlims]]}],
    Row[{"Plane of interest", InputField[Dynamic[poi]]}],
    Row[{"Variying variables", InputField[Dynamic[svars]]}],
    Dynamic[Plotslices[u, vars, varlims, poi, svars]]}]], {{z, 16, 
   "z"}, 0, 1, 0.0001}, Initialization :> (
   Plotslices[u_, vars_, varlims_, poi_, svars_] := 
     Module[{(*v1,v2,lv1, lv2,rv1,rv2,*)v1p, v2p},



      u /. poi[[1]] -> v1;
      u /. poi[[2]] -> v2;
      Print[u];
      v1p = poi[[1]];
      v2p = poi[[2]];
      posv1 = Position[vars, v1p][[1]];
      posv2 = Position[vars, v2p][[1]];
      lv1 = varlims[[posv1, 1]][[1]]; Print[lv1];
      lv2 = varlims[[posv2, 1]][[1]]; Print[lv2];
      rv1 = varlims[[posv1, 2]][[1]]; Print[rv1];
      rv2 = varlims[[posv2, 2]][[1]]; Print[rv2];
      psl = 
       Plot3D[u, {v1, lv1, rv1}, {v2, lv2, rv2}, 
        PerformanceGoal -> "Quality", Mesh -> None(*,
        ColorFunction\[Rule]Function[{x,y,z},Hue[z]]*), 
        ImageSize -> Medium];
      Return[psl];];
   )
 ]
POSTED BY: Erdem Uguz
u /. poi[[1]] -> v1;
u /. poi[[2]] -> v2;

this doesn't do anything, I think you meant:

u = u /. poi[[1]] -> v1;
u = u /. poi[[2]] -> v2;
POSTED BY: Sander Huisman
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract