필터 지우기
필터 지우기

How can I make derivatives with several variables?

조회 수: 20 (최근 30일)
Oscarin
Oscarin 2018년 9월 5일
편집: Oscarin 2018년 10월 23일
Hello I have a problem, I tryed to derive a equation like "a1^2*a2^2" but I got "ans = 2*a1*a2^2", This result is correct but If we take as variable only "a1" but I need to take as varible "a1" and "a2". I want to get this becase is a multiplication:
I have used diff () this is my code:
what is the correct way to say matlab which are my variables?
Thank you very much I wait for your answer.

채택된 답변

Walter Roberson
Walter Roberson 2018년 9월 15일
You can use gradient() to find the diff(), and you could sum() the result.
  댓글 수: 35
Oscarin
Oscarin 2018년 10월 17일
편집: Oscarin 2018년 10월 17일
when I use gradient (), I get a vector, [1,1] is the partial derivative of a variable, [2,1] is the partial derivative of another variable, this depend on the number of variables and GDL (Degrees of freedom) in this case GDL is 2 then we check the case whith "if GDL == 2 " therefore I get each position of vector and multiply for "w" if joint is rotate or cylindrical ("radio buttoms", art1 with value (1 or 3) y art2 with value (1 or 3)) and if joint is prismatic I multiply the position of vector by "y" (art1 with value (2), art2 with value (2)).
this is the simplified code for one case "GDL == 2" when I multiply variables.
if true
syms m g rt w1 w2 w3 y1 y2 y3
global Px Py Pz gdl
aux1 = Px + Py + Pz;
C = symvar(aux1)
D = setdiff(C,B)
F = setdiff(C,D)
aux2 = gradient(aux1,F)
if gdl == 2
art1 = str2double(get(handles.arti1,'String'));
art2 = str2double(get(handles.arti2,'String'));
if art1 == 2
aux5 = aux2(2,1)*y1;
else
aux5 = aux2(2,1)*w1;
end
if art2 == 2
aux6 = aux2(1,1)*y2;
else
aux6 = aux2(1,1)*w2;
end
aux2 = [aux5; aux6];
vel = sum(aux2);
vel = expand(vel);
end
Oscarin
Oscarin 2018년 10월 23일
편집: Oscarin 2018년 10월 23일
thanks my friend, I find the error you were right, I derivate the vector then square it, finally I use sum() and simplify then I get the result, sorry for a lot of question, this is my proyect to get my degree but I know about robotics but not about matlab and I am learning.
Thanks

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

D_coder
D_coder 2018년 9월 15일
편집: D_coder 2018년 9월 15일
You can try this
a = a1^2*a2^2;
diff(a,a1) + diff(a,a2);
ans =
2*a1^2*a2 + 2*a1*a2^2
  댓글 수: 1
Oscarin
Oscarin 2018년 9월 15일
thaks for your answer but this is more difficult because I am developing a graphic interphase and I export the data and I need to derivate de ecuation but I need to derive with a lot of variable I show a example:
In this case the last Graphic Interphase exported the data and I need to derive with variables "d1", "d2" and "t1". That's difficult because the ecuation it's different each time.
I have a list of possible variables but not all of them always appear because some of them based on the analysis become 0
Thanks

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Line Plots에 대해 자세히 알아보기

제품


릴리스

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by