# Varying constant in Matrix calculation to generate 3D plot

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;

• Where did you get the formulae you are using here? Feb 20, 2016 at 5:44
• 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. Feb 20, 2016 at 5:48
• 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. Feb 20, 2016 at 5:50
• Hi MacroB, Sure. I will try to reduce my code and edit again. Thank you for your comment. Feb 20, 2016 at 5:52
• I was asking you for a reference, actually. Is there a book/paper from which you got the formulae you are using? Feb 20, 2016 at 5:58

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}] 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.

• 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. Feb 20, 2016 at 18:23