Prev: Input a few vectors in order to generate a "Vector Field"
Next: Minimizing an Integral function
From: S O on 17 Feb 2010 05:26 Quiver will not calculate a vector field expression when I input constant vectors with their constant origins. I need something that does what I stated in the previous post. I need to be able to input constant vectors and get out a general expression, if it is possible. input constant vectors with constant origins: <0,4> at (-2,-2) <-4,-4> at (-2,2) <4,-4> at (2,-2) <0,4> at (2,2) <0,0> at (0,0) <0,2> at (-2,0) <0,-2> at (2,0) <2,0> at (2,0) <-2,0> at (2,0) Output a general vector field expression: F=<x-y,x*y> "Steven Lord" <slord(a)mathworks.com> wrote in message <hlfocv$hj1$2(a)fred.mathworks.com>... > > "S O" <sjo2008(a)gmail.com> wrote in message > news:hlf9ia$iqj$1(a)fred.mathworks.com... > >I am trying to write a code that has the following input output > >capabilities. I want to input (a few vectors & their origins) and output > >(a vector field expression). > > For example, input vector & origin pairs: > > <0,4> at (-2,-2) > > <-4,-4> at (-2,2) > > <4,-4> at (2,-2) > > <0,4> at (2,2) > > <0,0> at (0,0) > > <0,2> at (-2,0) > > <0,-2> at (2,0) > > <2,0> at (2,0) > > <-2,0> at (2,0) > > > > And output a vector field: > > > > F=<x-y,x*y> > > > > Is this possible? > > What is your desired output? Do you want a graph of the vectors? If so, > look at QUIVER. > > -- > Steve Lord > slord(a)mathworks.com > comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ >
From: Steven Lord on 17 Feb 2010 09:29 "S O" <sjo2008(a)gmail.com> wrote in message news:hlgg7t$br8$1(a)fred.mathworks.com... > Quiver will not calculate a vector field expression when I input constant > vectors with their constant origins. I need something that does what I > stated in the previous post. I need to be able to input constant vectors > and get out a general expression, if it is possible. > > input constant vectors with constant origins: > <0,4> at (-2,-2) > <-4,-4> at (-2,2) > <4,-4> at (2,-2) > <0,4> at (2,2) > <0,0> at (0,0) > <0,2> at (-2,0) > <0,-2> at (2,0) > <2,0> at (2,0) > <-2,0> at (2,0) > > Output a general vector field expression: > F=<x-y,x*y> Why that expression? The vectors you gave don't satisfy those relationships. For (-2, 0) you stated the result should be <0, 2> but by the expression F the result should be <-2, 0>. For (2, 0) your result is <0, -2> but F results in <2, 0> Anyway, yes you can do this as long as you know the general form of the vector field expression you want. It's simply a regression problem. http://www.mathworks.com/access/helpdesk/help/techdoc/data_analysis/f1-6010.html If the general form of the vector field expression you want is linear, then you can use backslash; if not, you'll probably need to use some of the regression/curve fitting tools in Curve Fitting Toolbox, Optimization Toolbox, or Statistics Toolbox. x = [-2 -2 2 2 0 -2 2 2 -2].'; % assuming the last (2, 0) above is a typo and should be (-2, 0) y = [-2 2 -2 2 0 0 0 0 0].'; c1 = [0 -4 4 0 0 -2 2 2 -2].'; % also assuming the values I mentioned above are the correct results c2 = [4 -4 -4 4 0 0 0 0 0].'; % for (-2, 0) and (2, 0) % If you know the expression for the first component is of the form a*x+b*y+c*x*y M = [x y x.*y]; abc = M\c1 % and you know that the second component is of the same form abc2 = M\c2 You should receive abc as [1; -1; 0] (indicating the first component is 1*x + (-1)*y + 0*x*y, or x-y as above) and abc2 as [0; 0; 1] (or something close to that due to roundoff error, indicating the second component is x*y.) If you don't know the general form of the expression, MATLAB doesn't have any functions that will "guess" the form directly for you. -- Steve Lord slord(a)mathworks.com comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ
From: S O on 17 Feb 2010 18:46 Thank you so much! Your code works beautifully, I am still trying to figure out how it really works. Does it have to do with orthogonal basis vectors? Anyway, is there to make it work for a off axis rotational vector field? (i.e. F=<uy+a,vx+b> ) Thanks ahead of time. "Steven Lord" <slord(a)mathworks.com> wrote in message <hlgug9$ooj$1(a)fred.mathworks.com>... > > "S O" <sjo2008(a)gmail.com> wrote in message > news:hlgg7t$br8$1(a)fred.mathworks.com... > > Quiver will not calculate a vector field expression when I input constant > > vectors with their constant origins. I need something that does what I > > stated in the previous post. I need to be able to input constant vectors > > and get out a general expression, if it is possible. > > > > input constant vectors with constant origins: > > <0,4> at (-2,-2) > > <-4,-4> at (-2,2) > > <4,-4> at (2,-2) > > <0,4> at (2,2) > > <0,0> at (0,0) > > <0,2> at (-2,0) > > <0,-2> at (2,0) > > <2,0> at (2,0) > > <-2,0> at (2,0) > > > > Output a general vector field expression: > > F=<x-y,x*y> > > Why that expression? The vectors you gave don't satisfy those > relationships. > > For (-2, 0) you stated the result should be <0, 2> but by the expression F > the result should be <-2, 0>. > For (2, 0) your result is <0, -2> but F results in <2, 0> > > Anyway, yes you can do this as long as you know the general form of the > vector field expression you want. It's simply a regression problem. > > http://www.mathworks.com/access/helpdesk/help/techdoc/data_analysis/f1-6010.html > > If the general form of the vector field expression you want is linear, then > you can use backslash; if not, you'll probably need to use some of the > regression/curve fitting tools in Curve Fitting Toolbox, Optimization > Toolbox, or Statistics Toolbox. > > x = [-2 -2 2 2 0 -2 2 2 -2].'; % assuming the last (2, 0) above is a typo > and should be (-2, 0) > y = [-2 2 -2 2 0 0 0 0 0].'; > c1 = [0 -4 4 0 0 -2 2 2 -2].'; % also assuming the values I mentioned above > are the correct results > c2 = [4 -4 -4 4 0 0 0 0 0].'; % for (-2, 0) and (2, 0) > > % If you know the expression for the first component is of the form > a*x+b*y+c*x*y > M = [x y x.*y]; > abc = M\c1 > % and you know that the second component is of the same form > abc2 = M\c2 > > You should receive abc as [1; -1; 0] (indicating the first component is 1*x > + (-1)*y + 0*x*y, or x-y as above) and abc2 as [0; 0; 1] (or something close > to that due to roundoff error, indicating the second component is x*y.) > > If you don't know the general form of the expression, MATLAB doesn't have > any functions that will "guess" the form directly for you. > > -- > Steve Lord > slord(a)mathworks.com > comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ >
From: S O on 19 Feb 2010 14:03 I figured out how to solve this problem but I am not sure how the code is working. I wold like clarification on the backslash operator. How does it work? Does it work on matrices and vectors differently? How is it different than the pseudoinverse operator? How does it apply to this code in particular?
From: Steven Lord on 19 Feb 2010 17:40 "S O" <sjo2008(a)gmail.com> wrote in message news:hlmn98$9sr$1(a)fred.mathworks.com... >I figured out how to solve this problem but I am not sure how the code is >working. > I wold like clarification on the backslash operator. > How does it work? > Does it work on matrices and vectors differently? > How is it different than the pseudoinverse operator? > How does it apply to this code in particular? Take a look at this page from the documentation -- it addresses most of your questions: http://www.mathworks.com/access/helpdesk/help/techdoc/math/f4-983672.html -- Steve Lord slord(a)mathworks.com comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ
First
|
Prev
|
Pages: 1 2 Prev: Input a few vectors in order to generate a "Vector Field" Next: Minimizing an Integral function |