0
$\begingroup$

As suggested, I rewrite my code to make it simpler and directly showing the problem. Here is a short example. I'd like to generate 3D plot where x,y,z (= a,b,answer) while I am varying a (0

a = 0.2(*constants*);
b = 0.5(*constants*);
matrix = RandomReal[{-1, 1}, {4, 2}];
matrix1 = matrix[[All, 1]];
matrix2 = matrix[[All, 2]];
inter1 = a/b matrix1;
inter2 = 1/b matrix2;
inter = inter1 + inter2;
answer = Total[inter]
$\endgroup$
8
  • 1
    $\begingroup$ Where did you get the formulae you are using here? $\endgroup$ Feb 20, 2016 at 5:44
  • 1
    $\begingroup$ Sungwoo, your question currently reads like a code dump. As @J.M. pointed out, you should show some background about what you are trying to calculate, reduce your code to a minimal working example, and indicate clearly why the output you currently obtain is not correct or acceptable. $\endgroup$
    – MarcoB
    Feb 20, 2016 at 5:48
  • $\begingroup$ Thank you for your comment. I wrote it using discrete oridnate method. As you can see, I am still a beginner on Mathematica, but trying to learn and improved. Thank you. $\endgroup$
    – SungwooY
    Feb 20, 2016 at 5:50
  • $\begingroup$ Hi MacroB, Sure. I will try to reduce my code and edit again. Thank you for your comment. $\endgroup$
    – SungwooY
    Feb 20, 2016 at 5:52
  • 1
    $\begingroup$ I was asking you for a reference, actually. Is there a book/paper from which you got the formulae you are using? $\endgroup$ Feb 20, 2016 at 5:58

1 Answer 1

1
$\begingroup$

One way to plot "answer" as a function of a and b is to build a function and then plot it.

matrix = RandomReal[{-1, 1}, {4, 2}];
matrix1 = matrix[[All, 1]];
matrix2 = matrix[[All, 2]];
ans[a_, b_] := Module[{},
   inter1 = a/b matrix1;
   inter2 = 1/b matrix2;
   inter = inter1 + inter2;
   Total[inter]];
Plot3D[ans[a, b], {a, 0, 3}, {b, 0, 3}]

enter image description here

For the particular function above, you can shorten this considerably to:

ans[a_, b_] := Total[a/b matrix1 + 1/b matrix2];

but I left it in a form more parallel to yours so that you can see more easily how to generalize to the case you have in mind.

$\endgroup$
1
  • $\begingroup$ Hi Bill, It works! I was able to apply this method on my long code to get 3D plot. Thank you for your help. I appreciate it. $\endgroup$
    – SungwooY
    Feb 20, 2016 at 18:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.