Borrar filtros
Borrar filtros

how can i make the differential of a function handle?

3 visualizaciones (últimos 30 días)
Sören
Sören el 30 de Dic. de 2014
Comentada: Star Strider el 31 de Dic. de 2014
Hello everybody,
in the following is a snippet from my program i wrote:
%Mein Programm:
syms t;
strp=input('Profil für Pitching:\n','s');
funp=str2func(['@(t)',strp]);
dT=input('delta time:\n');
% Folgende Werte werden nicht geändert:
funpdiff=diff(funp,t);
dT1=dT;
t=1024*dT;
t=double(t);
% Ende
% Pitch-Gradzahl, die gelaufen wird:
dTp1=dT;
kpI1=0;
while funpdiff(dTp1) >= 0
dTp1=dTp1+dT1;
end
Gp=abs(funp(0))+abs(funp(dTp1));
% Ende
It gives me the following errors:
Error using sym>checkindex (line 2429) Index must be a positive integer or logical.
Error in sym>privformatscalar (line 2376) checkindex(x);
Error in sym>privformat (line 2360) s = privformatscalar(x);
Error in sym/subsref (line 1578) [inds{k},refs{k}] = privformat(inds{k});
Error in Motion_To_PVT_Pitching_Soeren (line 25) while funpdiff(dTp1) >= 0
I don't know what they mean with a 'positive integer or logical'. I think the problem is with the differentiation of the function handle but i don't know how to avoid that, i need the differentiation of an input and then the values at certain points (which are also an input (dT,2dT,3dT and so on). And at the end also an integral of the differentiation which should be working then.
while funpdiff(dT) >= 0
p1=integral(funpdiff1,dT-dT1,dT)*Dp_M1;
v1=funpdiff1(dT);
p2=integral(funpdiff2,dT-dT1,dT)*Dp_M2;
v2=funpdiff2(dT);
p1=double(p1);
v1=double(v1);
p2=double(p2);
v2=double(v2);
fprintf('PVC= %.2f,%.2f,%.2f;\n',p1,v1,t);
fprintf('PVD= %.2f,%.2f,%.2f;\n',p2,v2,t);
dT=dT+dT1;
end
Thank you in advance for any help! I really need it. I am running out of time :(
Sören

Respuesta aceptada

Star Strider
Star Strider el 30 de Dic. de 2014
There are several problems in your code. I got it to work with some changes (I prefer inputdlg so I changed those lines and the lines following to produce compatible data). Those changes end after the assignment to ‘dT’.
I changed the assignments to ‘t’ to ‘t1’ because keeping the numerical assignments to ‘t’ prevented their being used as symbolic variables later in the code. You want to define ‘strp’ as a function of ‘t’, so this becomes a significant clarification. I cannot determine what you want to do with the variables I renamed ‘t1’, so I left them alone.
Because function handles (but not symbolic functions) lose their identities as functions when you differentiate them, you have to use the subs function to evaluate them.
This runs, but you will probably need to experiment with it to get the result you want:
%Mein Programm:
syms t;
strp=inputdlg('Profil für Pitching:\n','s'); % Change to ‘inputdlg’
funp=str2func(['@(t)',strp{:}]);
dT=inputdlg('delta time:\n'); % Change to ‘inputdlg’
dT=str2num(dT{:});
% Folgende Werte werden nicht geändert:
funpdiff=diff(funp,t);
dT1=dT;
t1=1024*dT;
t1=double(t1);
% Ende
% Pitch-Gradzahl, die gelaufen wird:
dTp1=dT;
kpI1=0;
while subs(funpdiff, t, dTp1) >= 0
dTp1=dTp1+dT1;
end
Gp=abs(funp(0))+abs(funp(dTp1));
% Ende
In the second part of your code, ‘funpdiff1’ and ‘funpdiff2’ are not defined (that I could discover), so I did not address the integrals. Note that to use the integral function, you will need to convert them to function handles, probably using matlabFunction.

Más respuestas (0)

Categorías

Más información sobre Function Creation en Help Center y File Exchange.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by