COMPGROUPS.NET | Search | Post Question | Groups | Stream | About | Register

• Email
• Follow

```Dear all,

I have a function u(t,x), which is dependent on both t and x. Now, i plotted a graph of u versus x, at various time points (i.e. i get several curves of u over x at different time points on the same plot).

The question is: how am i to find the gradient at a particular point on the graph? Let's say at u(t,2) and at all the time points?

I'm thinking of diff() and grad(). But what is the difference and how would i be able to set this up in my code?

Any help appreciated. Thankies!

Wendy
```
 0

See related articles to this posting

```"Wen Zhe " <wenzhe2092@hotmail.com> wrote in message <hor82t\$e7r\$1@fred.mathworks.com>...
> Dear all,
>
> I have a function u(t,x), which is dependent on both t and x. Now, i plotted a graph of u versus x, at various time points (i.e. i get several curves of u over x at different time points on the same plot).
>
> The question is: how am i to find the gradient at a particular point on the graph? Let's say at u(t,2) and at all the time points?
>
> I'm thinking of diff() and grad(). But what is the difference and how would i be able to set this up in my code?
>
> Any help appreciated. Thankies!
>
> Wendy

The functions, 'diff' and 'gradient', are considerably different.  The 'gradient' function allows you to specify variable-length intervals within your two independent variables, t and x in this case, if you so choose.  They do not have to be uniformly spaced apart.  Also it returns both (all) components of a gradient calculation.  However, be sure you read the description - the first component returned is for the second argument and visa-versa.

I can't be certain, but I suspect the approximations made by 'gradient' are of a higher than first order, possibly a cubic.  If not, there are undoubtedly some third-order gradients available in the file exchange.  I recall I wrote one for one of these threads quite some time ago, but I can't remember how to locate it now.

On the other hand 'diff' returns differences in only one direction - for you, in either the t direction or the x direction.  Also it assumes that the corresponding spacing is always in unit-length intervals.  In other words the values returned by 'diff' are strictly successive differences.  Consequently there are one fewer of them in whatever direction it is taken than in the input variable, whereas the vector or matrix returned by 'gradient' is always the same size as its input argument.

Roger Stafford
```
 0

```Thanks for the reply Roger.

So which one would you recommend that i use? grad() or diff()?

Wendy

"Roger Stafford" <ellieandrogerxyzzy@mindspring.com.invalid> wrote in message <horci0\$er4\$1@fred.mathworks.com>...
> "Wen Zhe " <wenzhe2092@hotmail.com> wrote in message <hor82t\$e7r\$1@fred.mathworks.com>...
> > Dear all,
> >
> > I have a function u(t,x), which is dependent on both t and x. Now, i plotted a graph of u versus x, at various time points (i.e. i get several curves of u over x at different time points on the same plot).
> >
> > The question is: how am i to find the gradient at a particular point on the graph? Let's say at u(t,2) and at all the time points?
> >
> > I'm thinking of diff() and grad(). But what is the difference and how would i be able to set this up in my code?
> >
> > Any help appreciated. Thankies!
> >
> > Wendy
>
>   The functions, 'diff' and 'gradient', are considerably different.  The 'gradient' function allows you to specify variable-length intervals within your two independent variables, t and x in this case, if you so choose.  They do not have to be uniformly spaced apart.  Also it returns both (all) components of a gradient calculation.  However, be sure you read the description - the first component returned is for the second argument and visa-versa.
>
>   I can't be certain, but I suspect the approximations made by 'gradient' are of a higher than first order, possibly a cubic.  If not, there are undoubtedly some third-order gradients available in the file exchange.  I recall I wrote one for one of these threads quite some time ago, but I can't remember how to locate it now.
>
>   On the other hand 'diff' returns differences in only one direction - for you, in either the t direction or the x direction.  Also it assumes that the corresponding spacing is always in unit-length intervals.  In other words the values returned by 'diff' are strictly successive differences.  Consequently there are one fewer of them in whatever direction it is taken than in the input variable, whereas the vector or matrix returned by 'gradient' is always the same size as its input argument.
>
> Roger Stafford
```
 0

2 Replies
537 Views

Similar Articles

12/8/2013 11:30:58 AM
[PageSpeed]

Similar Artilces:

Area under the curve
Hi, I have two sets of data t and y. I want to find the cumulative y (area under the curve) after each point of t and want to plot t with cumulative y. I tried trapz function. But trapz function gives the area at the last point of t, not at each point of t. Could you please help me to solve this problem? Kind regards, Dhina... "Dhina Siva siddarthan" <sdhinakaran@rediffmail.com> wrote in message <hhhqsv\$53p\$1@fred.mathworks.com>... > Hi, > > I have two sets of data t and y. I want to find the cumulative y (area under the curve) after each point.... I want to find the cumulative y (area under the curve) after each point of t and want to plot t with cumulative y. > > I tried trapz function. But trapz function gives the area at the last point of t, not at each point of t. Could you please help me to solve this problem? > > > > Kind regards, > > > > Dhina... > > a hint: > > help cumtrapz; > > us Thanks a lot, us!

how to plot curve fittings
I use baisc fitting to fit data set 1 to a curve 1, which is plotted on the same graph. When I try to fit data set 2 on the same graph. however, curve fitting 1 disappears. I wonder how to keep both fitting curves on the graph? boraw wrote: > I use baisc fitting to fit data set 1 to a curve 1, which is plotted > on the same graph. When I try to fit data set 2 on the same graph. > however, curve fitting 1 disappears. I wonder how to keep both > fitting curves on the graph? have a look at the "hold on" command Pluton pluton wrote: > > > > boraw wrote: >> I use baisc fitting to fit data set 1 to a curve 1, which is > plotted >> on the same graph. When I try to fit data set 2 on the same > graph. >> however, curve fitting 1 disappears. I wonder how to keep both >> fitting curves on the graph? > > have a look at the "hold on" command > > Pluton > > "hold on" is already used while plotting the data points. The fitting curve is plotted automatically during data fitting and "hold on" command does NOT work. > "hold on" is already used while plotting the data

Ploting MTF curve
Hello, I would like to plot my MTF curve. Here is code I´am using to calculate MTF: load image from file... inImg = double(inImg); inImg(:,:,4) = 0.2989 * inImg(:,:,1) + 0.5870 * inImg(:,:,2) + 0.1140 * inImg(:,:,3); % rgb to gray conversion for doubles for dim = 1:4 inImgCol = inImg(:,:,dim); for row = 1:size(inImgCol,1) ESF = inImgCol(row,:); % Take current image row as the ESF. LSF = diff(ESF); % The LSF is the derivative of the ESF. MTF = abs(fft(LSF)); % The MTF is the one side amplitude spectrum of the LSF. multiLineMTF(row,:) = MTF; % MTF of every row is stored in an array. end; mmlMTF(1,:,dim) = mean(multiLineMTF); % Spectra are averaged for smooth output. mmlMTF(1,:,dim) = mmlMTF(1,:,dim) / mmlMTF(1,1,dim); % Final MTF response is normalized to low-frequency value of 1 end; Well, but I don´t know how to plot it? I know that on X axes there will be spatial frequency and on Y axes there will be MTF, but how to do it? Thanks a lot

Self intersection of a 2d curve
Dear All, I have a curve in 2d that is piecewise linear, consisting of lines joining the points (x1,y1), (x2,y2),(x3,y3),... I would like to obtain estimates of the coordinates of the points where this curve intersects with itself. Any help is appreciated. Inf. Inf <infinitysquared@gmail.com> wrote in message <e0c27f69-1502-4b74-883b-92b8f0afae57@n75g2000hsh.googlegroups.c om>... > Dear All, > > I have a curve in 2d that is piecewise linear, consisting > of lines joining the points (x1,y1), (x2,y2),(x3,y3),... > > I would like to obtain estimates of the coordinates > of the points where this curve intersects with itself. > > Any help is appreciated. > > Inf. ------- With linear segments, you can get exact values rather than merely estimates. For any pair of line segments, you need to know whether they intersect and if so where that intersection is located. If P1 = (X1,Y1) and P2 = (X2,Y2) are the endpoints of one segment and P3 = (X3,Y3) and P4 = (X4,Y4) are the endpoints of the another segment, then they intersect if det ([X1,Y1,1,X2,Y2,1,X3,Y3,1]) and det([X1,Y1,1,X2,Y2,1,X4,Y4,1]) are of opposite sign

regarding fixdt
When I mention the data type as fixdt(0,8,3) in a constant block, The total wordlength is 8bits, fractional length is 3 bits. So the remaing 5 bits allocated for integer part. So If I enter any value greater than 32, simulink throws overflow error. This is clear for simulation. However when I generate code for a particula simulink block with the datatype mentioned as fixdt(0,8,5) The corresponding signal is assigned with the datatype uint8 and no restriction on bitsize. It seems the signal with datatype fixdt(0,8,3) can hold the value 255 even. Making the datatype fixdt(0,8,3)/ uint8 has no d

Curve Fitting
Hello Everybody, I am having a hard time fitting a user-defined function to a set of data.I have two columns of data namely 'x' and 'y' (all contained in two columns of a Excel spread sheet) and I have an equation reading y=f(x) containing 'n' number of parameters. I would like to fit the function to the 'graph' drawn by "plot (x,y,'o'). I there are errors creeping in. My function is : y = 0.25*(cosd(B)).^2*(k*h).^2*((cosd(A)/(cosd(B)).^2)*(-(C+(C*E*(sind(t)).^2.*(cosd(x)).^2)/(C+E*(cosd(t)).^2))*(cosd(B)).^2+1-((sind(B

Need Curve/Curve intersection algorithm
I have a set of 2D discrete points (Xi, Yi) forming a curve segment along a semi-horizontal line, and another set of points (Xj, Yj) forming a curve cutting across the previous curve. I want to find their intersection. Could anyone please kindly send me a C code to lideng@yahoo.com for that? Lideng Ni <lideng@yahoo.com> wrote: > I have a set of 2D discrete points (Xi, Yi) forming a curve segment > along a semi-horizontal line, Care explaining what you mean by "semi-horizontal"? And what makes a curve segment be "along" a line? What do you know about that "curve", to begin with, besides the set of discrete points? If nothing, that means you don't have a curve to start with, but a polyline. > and another set of points (Xj, Yj) forming a curve cutting across > the previous curve. I want to find their intersection. > Could anyone please kindly send me a C code to lideng@yahoo.com for > that? No. USENET is not a write-only medium. -- Hans-Bernhard Broeker (broeker@physik.rwth-aachen.de) Even if all the snow were burnt, ashes would remain.

How to measure execution time of Cg programs
Hi, Do You know how can I measure execution time of Cg programs in OpenGL e.g. in FPS or in second. Can I use some system timer to get a first time before execution of render function and the second time after execution of render function. Will the difference (between this two times) be correct value or there is some other way to get a execution time. I have ATI Radeon graphic card. Thanks, RK. krraf@wp.pl schrieb: > Hi, > Do You know how can I measure execution time of Cg programs in OpenGL > e.g. in FPS or in second. > Can I use some system timer to get a first time before ex

warning #2 401471
Hi, When I run my simulink, the warning below came out. Can someone explain to me about this warning. Warning: Unable to reduce the step size without violating minimum step size of 3.229357210457347e-014 at time 9.089832456038741. Continuing simulation with the step size restricted to 3.229357210457347e-014 and using an effective relative error tolerance of 0.001435080569729471, which is greater than the specified relative error tolerance of 0.001. >>

Database Conversion Help Needed
A couple of months ago, a user, Zott!, asked about converting a database with the letters "RMKF" in them. He said that he was trying "Data Junction", but never reported back if it worked or not. I have the same delimma. I'm running Geac/Concord CS2000 under DOS. I'm having trouble accessing some records due to the fact that the copy of CS2000 I have was never completely updated to Y2K compliance. Some portions are, like the section for adding GL Journal Entries, but, some sections aren't, like the Inquiry/Reports section. As a result, one can enter a journ