이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
Creating phase plot from initial data
조회 수: 5 (최근 30일)
이전 댓글 표시
I have a data table with no associated function, is it possible to generate the vector field and phase diagram from this? GS.
댓글 수: 2
Gavin Seddon
2017년 11월 15일
You are welcome, I have tried the arc tangent with my table and it appears I should define two points and calculate the angle. Also I cannot calculate the gradient since it complains that my matrix is not equal, Possibly because I am using fxy (multivariate). Nevertheless I have been of data now to complete the job. GS.
채택된 답변
Star Strider
2017년 3월 30일
Use the gradient function to create the derivatives.
See if this works with your data:
x = sin(0:0.5:2*pi*2); % Create Data
y = cos(0:0.5:2*pi*2); % Create Data
u = gradient(x); % Calculate ‘x’ Derivative
v = gradient(y); % Calculate ‘y’ Derivative
figure(1)
quiver(x, y, u, v)
grid
axis equal
댓글 수: 78
Gavin Seddon
2017년 3월 31일
Hello Star Strider thank you by doing this is it attempting to locate a 'ubiquitous' function? Also I will investigate Quiver immediately however I will attempt your solution on Monday. GS.
Star Strider
2017년 3월 31일
My pleasure.
My code assumes that your data are reasonably continuous and have very low noise. (Taking the derivative significantly amplifies noise, so doing some empirical curve-fitting, perhaps with the polyfit and polyval functions may be necessary.) All of these are core MATLAB functions.
Have a restful weekend!
Gavin Seddon
2017년 4월 10일
편집: Gavin Seddon
2017년 4월 10일
hello Star Strider
I have isolated a curve which I am repeating your process.
I have the fx and it appears fy is its derivative.
Is this true and if so will you explain why this is
the case since I have never considered this? GS.
Star Strider
2017년 4월 10일
I have no idea what your data are, so I cannot comment on them.
If you calculated ‘fy’ by using the gradient function on ‘fx’, ‘fy’ would be the numerical derivative of ‘fx’.
Gavin Seddon
2017년 4월 12일
Thank you, I was unsure if fy was indeed the derivative and you have confirmed this (which was my question). I never considered this before. GS.
Gavin Seddon
2017년 4월 13일
Apologies Star Strider My Data Gives the Error Error using quiver (line 44) DOUBLE cannot convert the input expression into a double array. Does this mean my data is incompatible? GS.
Star Strider
2017년 4월 13일
‘Does this mean my data is incompatible?’
Not necessarily. It depends where you got it (for example, a symbolic calculation) and the data type or array type (table, structure, cell, etc.). If it is a symbolic calculation with a symbolic variable, you first must remove the symbolic variable. (Sometimes, using vpa or vpasolve will work.) For the other array types, you will have to extract each vector from them as a double array in order to use the plot and quiver functions.
What you need to do depends on what you are starting with.
Star Strider
2017년 4월 13일
My pleasure.
You too!
You can probably use the table2array function. This creates a matrix from your table, so you can access your data as you would normally access the data in a matrix. Choose the appropriate columns (or rows).
It converts only numerical data, not categorical data or column headers. From your description of what you want to do, I doubt this will be a problem in your application.
See the documentation for the function. It has links to related functions that may be more appropriate for what you want to do.
Gavin Seddon
2017년 4월 18일
Hello Star Strider, these commands as you said fit my data better. May I also use a higher function (I used primary for simplicity I would use cubic)? Your suggestion for using matrices has made me look at iterative mapping was this your idea? Thank you. GS.
Star Strider
2017년 4월 18일
My pleasure.
I would not use a polynomial fit of higher order than 7, and usually 3 will be adequate.
My impression is that your data (originally a table, extracted to a matrix) are already a matrix. I am not certain what you mean by ‘iterative mapping’. You can fit matrix variables with a number of different approaches (depending on what you want to do), and there are several iterative nonlinear function fitting functions available in MATLAB and various Toolboxes.
Gavin Seddon
2017년 4월 19일
Hello again, I was correct you have perceived that my data is non-linear (Lorentz used iterative mapping). For this reason I would rather avoid 'tailoring' it or using high polynomials. I will try both polyfit and a cubic function. Will you suggest toolboxes for non-linear plotting and perhaps chaos investigation? Finally, if I encounter any issues with polyfit I will put that on a new thread. Thanks again. GS.
Star Strider
2017년 4월 19일
My pleasure.
There are several nonlinear parameter estimation (and related) functions available. The Statistics and Machine Learning Toolbox nlinfit, and the Optimization Toolbox lsqcurvefit functions are options. I don’t have the Curve Fitting Toolbox, so I can’t comment on it.
I’ve not done anything with chaos theory in a long time, so I’m not familiar with using MATLAB for it. The File Exchange may have contributions that would do what you want.
The polyfit function will only fit vector data, nlinfit will fit matrix independent and vector dependent variables, and lsqcurvefit will fit matrix independent and dependent variables.
Gavin Seddon
2017년 4월 21일
Hello star Strider The Cubic Function failed with the same error so I am looking into the non-linear nature of my work. Thank you it appears lsqcurvefit maybe appropriate. I will be absent until the end of next week at which time I will submit a new question since I cannot see how to create the initial function for use with lsqcurvefit. Your initial answer was perfect. GS.
Star Strider
2017년 4월 21일
Thank you!
In your new Question, please describe your data (and include it as a file if possible) and what you want to do, and post the equations you are fitting (as a posted image of them as well as code), since not everyone who can help you may be familiar with it. That ‘Lorenz used iterative mapping’ to solve it means that it may not be among my areas of expertise, although if I have an understanding of the approach you want to take, and if coding is the only problem, my knowing the details of what you are doing may not be necessary.
I am certain at least one of us here will be able to help you if we have a reasonable understanding of what you want to do.
Gavin Seddon
2017년 4월 21일
Hello again, that is wonderful. I have measured a change in position of a molecule within a cell (recorded in a table). When plotted it is clearly sinusoital suggesting rotation of the body. Hence I attempted a vector plot (you know the rest here). The more I consider the curve it appears more non-linear. Is it possible to use lsqcurvefit to derive a function? GS.
Star Strider
2017년 4월 21일
Thank you!
The lsqcurvefit function will fit data to a function, but will not derive one for you.
The Symbolic Math Toolbox would help with the symbolic calculations of the model function you want to derive, and will even generate MATLAB code from it (using the matlabFunction function) that you can use as your objective function for lsqcurvefit. The Symbolic Math Toolbox has its limits, and we can help you deal with them.
Gavin Seddon
2017년 4월 23일
This is really good. I may have devised a method for determining molecular co variability which may be used with three-dimensional quiver. I must leave now. Thanks. GS.
Star Strider
2017년 4월 23일
It would be terrific if the method you devised is sufficiently novel to be worthy of publication!
See you later!
Gavin Seddon
2017년 4월 27일
Hello Star Strider, I will install the necessary toolbox and investigate this. No doubt Guy will need further help with this. GS.
Star Strider
2017년 4월 27일
I will probably be able to help you with any programming problems. I’m not certain about the physics.
Gavin Seddon
2017년 4월 29일
Hello again, it appears symfun will generate the symbolic function. Would this fit in my data better because prima facie it appears not to use my data? Will you directly further please? GS.
Star Strider
2017년 4월 29일
The symfun function allows you to create a symbolic function, then manipulate it symbolically so that it does what you want.
To use it in your numeric MATLAB script, you then have to use the matlabFunction function to create an anonymous function or a function file from it (your decision, so choose whatever is most appropriate). You can then use that function in your numeric MATLAB code. (Print the anonymous function to the Command Window by removing the parenthesis from the end of the matlabFunction call, then copy it and paste it into your numeric calculation script.) Then you can call the function from your script, just as you would any other function.
Please read through the documentation on matlabFunction thoroughly. It has a number of options that can make your task significantly easier.
I don’t know what your symfun function is, so look through the documentation on the odeToVectorField function as well to see if it could be applicable. Use it before you call matlabFunction.
It is best not to do extensive or recursive calculations in the Symbolic Math Toolbox, unless you need its extended-precision calculation ability. It isn’t optimised for such calculations, and is extremely slow, when compared to doing the same calculations in non-symbolic code.
Gavin Seddon
2017년 5월 3일
I have read your suggestions however the very basic problem of constructing a non-linear curve/function eludes me. I was wondering if * lsqcurvefit* with the basic fitting UI is the way ahead; followed by your procedure or perhaps * quiver* used? GS.
Star Strider
2017년 5월 3일
I thought you already had your function and only need to express it as MATLAB code. I will do my best to help with that if you need it. (That may be the limit of my ability to help, since the physics of what you are doing may be outside my areas of expertise.)
The lsqcurvefit function will likely do what you want. It has several advantages, specifically the ability to fit matrix dependent variables, and the ability to constrain the parameter values. The disadvantages are that while parameter confidence intervals are possible (if I remember correctly), statistics on the fit (prediction confidence intervals) and some other statistics are not available. I am not familiar with the UI for it, since I use the script commands.
The quiver function is not difficult. It requires the (x,y) coordinates of the data, and the derivatives of the curve in the (x,y) directions to specify the arrows. An easy way to calculate those are with the gradient function.
Gavin Seddon
2017년 5월 4일
Thank you Star Strider that is wonderful and please don't worry about the biophysics/biochemistry. GS.
Gavin Seddon
2017년 5월 8일
Hello star strider, I have given this issue plenty of thought over the weekend and I presume the way ahead will be: nlinfit which I hope will generate a better fit to my initial cubic function. Then in order to produce a less 'messy' function a symbolic function can be used employing symfun which is subsequently used to form the handle by matlabfunction then this can be imported into your protocol for the production of the vector field. However I have found it is better to use dIff for symbolic functions. No doubt during the work I will need help I hope this is okay? GS.
Star Strider
2017년 5월 8일
If you are fitting matrix dependent variables, you must use lsqcurvefit. For vector dependent variables, both nlinfit and lsqcurvefit will work. (I still do not completely understand what you are doing.)
I do not understand using the diff function unless you want to create an ODE function to use with a numeric solver (for example ode45), or if you are fitting derivatives of data.
I will of course help as much as I am able.
Gavin Seddon
2017년 5월 11일
Hello, when I add the variable using syms Matlab immediately evaluate the function and removes the constants. Is it possible within the variable to retain the constants within the function and proceed with the protocol? GS.
Star Strider
2017년 5월 11일
The only thing I can think of is to comment-out the values of the constants. It won’t substitute them if it has nothing to substitute them for.
Gavin Seddon
2017년 5월 15일
Hello Star Strider you were perfectly correct on the non-linear issues, it appears lsqcurvefit is the command to use. However it pays unnecessarily difficult to use and that I will continue with using symfun. GS.
Gavin Seddon
2017년 5월 15일
편집: Star Strider
2017년 5월 15일
Hello again, I have processed the following, will you advise further sold the function becomes symbolic?
fs = symfun(x + y, [x y])
fs(x, y) = x + y
eval fs
fs(x, y) =
x + y
GS.
Star Strider
2017년 5월 15일
Hi. ‘fs’ is a symbolic function as you have defined it.
You can convert it to an anonymous function to use in numeric code with the matlabFunction function.
Gavin Seddon
2017년 5월 15일
Hello, my initial function fx was generated using a table of two columns labelled time and distance however my function uses x. I created fs using x and y according to the manual. Whilst I follow the Matlabfunction command how do I relate distance, time to the functions? This is probably obvious but I am missing a fundamental point. Thanks for your help. GS.
Star Strider
2017년 5월 15일
You can name the function variables anything you want. (I would of course not add ‘time’ and ‘distance’ since the units are different.)
Is something like this what you want?
syms t d v
v(t,d) = d/t; % Calculate Velocity As Function Of Distance & Time
v = matlabFunction(v)
v =
function_handle with value:
@(t,d)d./t
Gavin Seddon
2017년 5월 16일
did you need *matlabfunction* and by function_handle the actual function? I didn't understand the last part or is that he symbolic notation? GS.
Star Strider
2017년 5월 16일
The matlabFunction function creates a function handle to the anonymous function code it creates. You can then call it as any other function, for example:
d = [0 1.0 1.5 2.5 4.0 4.5 4.1 2.0 1.0];
t = [1 1.5 2.0 2.5 2.7 3.0 3.8 4.0 4.5];
velocity = v(t,d);
I am a bit lost. I am not certain what you are asking. I want to help as much as I can.
Gavin Seddon
2017년 5월 16일
This did not print your answer was slightly confusing, did you mean the matlabfunction command and then did you mean your final handle is symbolic? GS. My previous attempt was corrupted, sorry.
Star Strider
2017년 5월 16일
No worries.
The matlabFunction function converts a symbolic function to an anonymous function (or a function file) to use in numeric (non-symbolic) MATLAB code.
Gavin Seddon
2017년 5월 16일
Thank you for the understanding, I now have my original function fx which has the equation, a symbolic function fs, which I created previous but I don't know how this relates to fx. If successful if I could relate these I assume fx = fun; fm = matlabfunction (fx) am I preceding correctly. GS.
Star Strider
2017년 5월 16일
My pleasure.
Your code is correct if ‘fx’ is symbolic.
If one is a function of the other, and they both begin as symbolic functions, consider using the Symbolic Math Toolbox compose function.
Gavin Seddon
2017년 5월 17일
Hello, are you suggesting; hybridising my symbolic function and the initial function fx to produce a new function which may then be passed to matlabfunction to enable the formation of the anonymous function? The compose command appears difficult (to me). Alternatively is it possible to transform fx into a symbolic function directly? Thanks. GS.
Star Strider
2017년 5월 17일
I’m not certain where we’re starting from, here. If both ‘fs’ and ‘fx’ are symbolic functions, you can manipulate them in the Symbolic Math Toolbox and then use matlabFunction to convert them to anonymous functions to use in numerical calculations. (The Symbolic Math Toolbox can do one-off numerical calculations. It is extremely inefficient for iterative calculations.)
If you want to manipulate your anonymous function in the Symbolic Math Toolbox, you have to create it new as a symbolic function. (This is a relatively simple copy-paste of everything except the function handle designation. It may be necessary to remove the dot-operators for element-wise calculations.) You can use it as an anonymous function in your symbolic code, however since it exists as a function handle, and not a symbolic object, you cannot do much with it as an anonymous function in the Symbolic Math Toolbox.
To Illustrate —
syms x y
anon_fcn = @(x) x.^2 + 5*x - 2; % Anonymous Function
out = anon_fcn(y); % Substitutes ‘y’
% q1 = diff(anon_fcn); % Throws Error
sym_fcn = symfun(x.^2 + 5*x - 2, x); % Creates Symbolic Function
q2 = diff(sym_fcn); % Calculates Derivative
Gavin Seddon
2017년 5월 17일
Hello yes to your initial suggestion however you mentioned 'manipulate them' using the symbolic toolbox. May We proceed from this please? Incidentally yes my function from the curve is both cubic and was defined as symbolic fx it was my mistake to talk of fs, sorry for the confusion. GS.
Gavin Seddon
2017년 5월 17일
Hello my first investigation gave simplify and subs however it is clear how these may help. GS.
Star Strider
2017년 5월 17일
I intended by ‘manipulate them’ that they must be symbolic objects. (It is not possible to use anonymous-function function-handles as symbolic objects in the sense that you can use them as anything other than anonymous functions. It is not possible to do anything else with them.)
You can apply all the appropriate Symbolic Math Toolbox functions to your symbolic objects.
No worries about the typographical error between ‘fx’ and ‘fs’. Thank you for sorting that though, because I thought they were different and that one was an anonymous function and the other a symbolic function.
Gavin Seddon
2017년 5월 17일
Thank you, when it is convenient will you direct me. I will be absent from Sunday until the following Friday (that is why I am obsessive with this, I am assuming it will prove necessary for the partials plot and vectors). GS.
Gavin Seddon
2017년 5월 18일
Thank you, considering this problem I fear Matlab indicated initially that it should not be expressed 2 dimensionally. I think we have given this appropriate consideration, I have simplified the function (it is still long). I will now produce the table listing the multivariable values and proceed with three-dimensional quiver. GS.
Star Strider
2017년 5월 18일
My pleasure.
Be careful using gradient with a matrix, since it takes the derivatives across both rows and columns. I would use it on each vector separately to calculate the directional derivatives for quiver3, if that is what you want to do. See the documentation on gradient for details.
Gavin Seddon
2017년 5월 19일
I have started the multivariable approach. I am using the partial differential toolbox. Should I treat my data in a similar fashion to your original suggestion? Also do you know of any additional approaches that will benefit this work? After tomorrow I will be absent so please do not assume my lack of interest. GS.
Star Strider
2017년 5월 19일
I have the Partial Differential Equation Toolbox but I’ve not used it in several years.
If you have a differential equation, you will be able to calculate the derivatives from your differential equation function and the solved differential equation output. It may not be necessary to use the gradient function.
I’ll be here to help as I can.
Gavin Seddon
2017년 6월 1일
Hello, I have created a multivariable table, it is possible to load its data to pdetool to use with a mesh and then generate a cubic equation? Thank you. GS.
Star Strider
2017년 6월 1일
I have the Partial Differential Equation Toolbox, but haven’t used it in years. It would take me a while to come up to speed with it.
So my preliminary reply is for you to experiment with it.
Gavin Seddon
2017년 6월 2일
Hello I have plotted the data using cftool it is explainable in that both residues rotating simultaneously producing a Unremarkable plane. However the resulting function is very complex. I am hoping the partial toolbox produces a simpler function. Considering its methods and I suspect it may be necessary plot the graph with Matlab and put this into pdetool. Thanks. GS.
Gavin Seddon
2017년 6월 5일
Hello on close examination the plot is very acceptable and therefore I am proceeding with using cftool.
Star Strider
2017년 6월 5일
Congratulations on finding the solution! I’d like to see a PDF of a paper you publish on this, because I’d like to understand what you’re doing.
I do not have the Curve Fitting Toolbox, so I cannot help you with its functions.
Gavin Seddon
2017년 6월 6일
편집: Stephen23
2017년 6월 6일
Hello, indeed my pleasure. However as a final attempt at the quiver3, I have the function
fxy =
(8589*x)/10000 + (9749*y)/1000 + (1211*x*y)/1000 - (1077*x^2*y)/500 + (5469*x^2)/10000 - (2249*x^3)/2500 - (321*y^2)/50 + 1869/200
Matlab gives fxy which is z but the manual requires w which would make sense since I plotted XY and Z. Would the differential of my function give W? GS.
Star Strider
2017년 6월 6일
The problem is that is an assignment, not a function. If you want to use it as a function, you construct is as:
fxy = @(x,y) (8589*x)/10000 + (9749*y)/1000 + (1211*x.*y)/1000 - (1077*x.^2.*y)/500 + (5469*x.^2)/10000 - (2249*x.^3)/2500 - (321*y.^2)/50 + 1869/200;
I have no idea how ‘W’ relates to ‘X’ and ‘Y’, so I cannot answer that.
If you want to calculate and plot the surface normals, this works:
fxy = @(x,y) (8589*x)/10000 + (9749*y)/1000 + (1211*x.*y)/1000 - (1077*x.^2.*y)/500 + (5469*x.^2)/10000 - (2249*x.^3)/2500 - (321*y.^2)/50 + 1869/200;
x = 0:9;
y = 1:9;
[X,Y] = meshgrid(x,y);
Z = fxy(X,Y);
[U,V,W] = surfnorm(Z);
figure(1)
mesh(X, Y, Z)
hold on
quiver3(Z, U, V, W, 0.01)
hold off
Gavin Seddon
2017년 6월 7일
Hello Star Strider
Thank You for this. It is terrific. I will send the results but it may take a little time. GS.
Gavin Seddon
2017년 11월 14일
Hello the derivative gives the magnitude, is it possible to quantify the direction? GS.
Star Strider
2017년 11월 14일
I am not certain what you want.
The atan2 or atan2d functions will return an angle. I would do something like this:
angl = atan2(dy, dx);
Gavin Seddon
2017년 11월 15일
Hello, I only want to give value for the position for the vector. This appears splendid. Another part of the multivariable treatment would be to calculate the initial gradient. This will be negative and complement my molecular motion figure in that the direction will be negative. Confusing but the article will make sense. Thank you. GS.
Gavin Seddon
2018년 3월 6일
Hello Star Strider to analyse this further. If the directional derivative is divided by its magnitude I will get the unit vector. Is it possible to create a figure of this arrow? This may then be superimposed upon a grid for analytic geometry. This will enable me to calculate the angle with the adjacent (X (time)). I may then give a direction quantitatively.? many thanks. GS.
Gavin Seddon
2018년 3월 6일
Hello, yes this looks perfect. It appears I do not need to transpose the arrow to extract data. At first look I cannot see how to place the arrow into a new figure, will it allow me to do this? Yet again a perfect answer. Thank you. GS.
Gavin Seddon
2018년 3월 7일
Hello, initially is the direction calculated from the two dependent variables? The Y is expected however Z is e 10; is this a product? Also is the direction a consequence of their interaction? GS.
Star Strider
2018년 3월 7일
편집: Star Strider
2018년 3월 7일
I am not certain what you are referring to.
For an illustration of how quiver works (in this instance quiver3), see: Draw Triangle using quiver3 command in Matlab (link)
—————————
EDIT —
I have no idea what ‘Z’ is or how you calculated it. I have no explanation for its magnitude being 1E+10. If you provide more details, I will do my best to explain it.
Gavin Seddon
2018년 3월 21일
Hello, I have decided the best way forward is to draw a labelled triangle. Then using my derivative as the absolute hypotenuse Value, then the angle cos = adjacent/hypotenuse. Thank you. GS.
추가 답변 (0개)
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 MathWorks 사이트 방문이 최적화되지 않았습니다.
미주
- América Latina (Español)
- Canada (English)
- United States (English)
유럽
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom(English)
아시아 태평양
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)