MATLAB: Multiple variable analysis representation

multiple variablesvisualisation

I would like to make a graphical representation of a function with multiple parameters for an electronic design. I only need the maximum and minimum values for each x value (see example)
My spice program is limited to two parameters and can’t show only the minimum and maximum lines.
Example:
y=ax^3+bx^2 +c+d
Variables:
  • y=function outcome
  • a=range (1-10 step 1) ->11 values
  • b=range (5-50 step 5) ->10 values
  • c=range (0.1-1 step 0.1) ->10 values
  • d=range (3-30 step 3) ->10 values
  • ymax=function outcome maximum
  • ymin=function outcome minimum
I also need to know the values of all the parameters(a,b,c,d) of ymax and ymin. I could make a loop-in-loop-in-loop…. construction, but maybe someone already made a script and a visualization or has a better idea.
Kind regards, Peter

Best Answer

[A, B, C, D] = ndgrid(1:10, 5:5:50, 0.1:0.1:1, 3:3:30);
y = A .* x.^3 + B .* x.^2 + C .* x + D;
[miny, minidx] = min(y(:));
[maxy, maxidx] = max(y(:));
parms_at_min = [A(minidx); B(minidx); C(minidx); D(minidx)];
parms_at_max = [A(maxidx); B(maxidx); C(maxidx); D(maxidx)];
If you have multiple X values then
numx = length(x);
[A, B, C, D, X] = ndgrid(1:10, 5:5:50, 0.1:0.1:1, 3:3:30, x);
y = A .* X.^3 + B .* X.^2 + C .* X + D;
rsy = reshape(y,[], numx);
[miny, minidx] = min(rsy); %first dimension

[maxy, maxidx] = max(rsy); %first dimension
parms_at_min = [A(minidx); B(minidx); C(minidx); D(minidx)];
parms_at_max = [A(maxidx), B(maxidx), C(maxidx), D(maxidx)];
I make no claims that this is the most efficient way.