0

I have the following code:

f1_p1 = @(xq1) interp1(x_j1,p1,xq1);
f2_p1 = @(xq2) interp1(x_j2,p1,xq2);
new_p1x1 = @(xq1,xq2) f1_p1(xq1).*f2_p1(xq2);

To plot f1_p1 and f2_p2 is easy, I do:

fplot(f1_p1, [30,70])

My question

How can I plot the second function (new_p1x1)? I have tried the same as before but it doesn't work....(fplot(new_p1x1, [30,70])) I get:

Error using @(xq1,xq2)f1_p1(xq1).*f2_p1(xq2)
Not enough input arguments.

Thanks for your help!!!

Sergio Haram
  • 437
  • 4
  • 17

1 Answers1

1

When using

fplot(new_p1x1, [30,70])

[30,70] is considered as 1x2-matrix and thus only as one argument, while new_p1x1 requires two. Thus you can call either

new_p1x1(30, 70) # 30 is passed to f1_p1 and 70 to f2_p2

or

new_p1x1([30,70], [30,70]) # The matrix [30,70] is passed to both function.

I cannot tell, which solution is more useful for you, it depends on what you want to to.

However, it seems, fplot only accepts functions with one argument. So it seems, you have to use one of the 3D plotting functions.

For 3D plotting, you can use e.g. surf.

[x1,~] = fplot(f1_p1, [30,70]); % Returns a useful number of x-values for f1
[x2,~] = fplot(f2_p1, [30,70]); % Returns a useful number of x-values for f2

[X,Y] = meshgrid(x1,x2);

surf(x1,x2,new_p1x1(X,Y)); % x1 (X) is passed to f1, x2 (Y) is passed to f2
Nemesis
  • 2,324
  • 13
  • 23
  • I have problems using a 3d plotting for functions in matlab. Could you help me with this! It is so frustrating... I have tried `ezplot(fy1,[30,70])` but it returns a plot of `xq1 vs. xq2`... I have also tried `ezplot(fy1,[30,70],[30,70])` but the result is the same... – Sergio Haram Oct 20 '14 at 08:30
  • I have added some code for 3D plotting. Please tell if this is the plot you need. – Nemesis Oct 20 '14 at 11:06
  • That's good. Sorry for the confusion in my first version of the answer. – Nemesis Oct 20 '14 at 11:10