Torsten
Posts:
1,684
Registered:
11/8/10


Re: Calculating a function
Posted:
Mar 5, 2014 6:20 AM


"canon " <canexp4@gmail.com> wrote in message <lf5v47$khd$1@newscl01ah.mathworks.com>... > TideMan <mulgor@gmail.com> wrote in message <4cf3e6a30939448a8bc761c486eb8de9@googlegroups.com>... > > On Wednesday, March 5, 2014 1:30:11 PM UTC+13, canon wrote: > > > Hi There > > > > > > > > > > > > I have a function f(x,y) and x=[a,b] and y=[c,d]. a, b, c and d are discrete variables. My question is I have to combine variable a,b, c and d and for each pair of (x,y) calculate f. How can I do that? > > > > > > > > > > > > Thanks > > > > It depends whether the function will accept x and y as scalars or vectors or matrices. > > If it will accept matrices, it's easy: > > x=linspace(a,b,nx); % nx is the no of points in x > > y=linspace(c,d,ny); % ny is the no of points in y > > [X,Y]=meshgrid(x,y); > > out=f(X,Y); > > Thank you very much. To make my point more clear assume x=[2, 4, 5, 9] and y=[1, 4, 2, 8]. Technically we have 4*4=16 pairs of (x,y) and need 16 value for f. Could you please help me out? > > thanks
Did you even read Tideman's answer ? If instead of > > x=linspace(a,b,nx); % nx is the no of points in x > > y=linspace(c,d,ny); % ny is the no of points in y you write x=[2, 4, 5, 9]; y=[1, 2, 4, 8]; you are done.
Best wishes Torsten.

