- You will see updates in your activity feed.
- You may receive emails, depending on your notification preferences.

- 4 questions asked
- 0 answers
- 0 accepted answers
- reputation: 0

- 4 questions asked
- 0 answers
- 0 accepted answers
- reputation: 0

Accepted Answer by Walter Roberson

- 30 questions asked
- 40,358 answers
- 15,346 accepted answers
- reputation: 79,453

9 views (last 30 days)

9 views (last 30 days)

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.

- 30 questions asked
- 40,358 answers
- 15,346 accepted answers
- reputation: 79,453

Answer by Walter Roberson
on 15 Sep 2018

- 30 questions asked
- 40,358 answers
- 15,346 accepted answers
- reputation: 79,453

Accepted Answer

thaks for your answer but this is 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

Walter Roberson
on 16 Sep 2018

- 30 questions asked
- 40,358 answers
- 15,346 accepted answers
- reputation: 79,453

gradient() automatically takes the derivative with respect to each of the unbound variables in the expression. Since you are adding them all together and symbolic addition is commutative, you do not even need to know what order of variables it used.

You can use symvar() to detect which variables were used in an expression, if you need to.

when I tryed with gradient () matlab took all varibles.

Are there some way to say to matlab which of my simbolic variables takes like varibles?

For example in a ecuation I have "d1", "t1" and "d2", I need to derivate at one time but I need to derivate only about "t1" and "d2", I want "d1" like a constant.

Is this possible?

thanks

- 30 questions asked
- 40,358 answers
- 15,346 accepted answers
- reputation: 79,453

Ok, I am learning but I don't understand how can I do derivatives, I try this.

Thanks.

Walter Roberson
on 17 Sep 2018

- 30 questions asked
- 40,358 answers
- 15,346 accepted answers
- reputation: 79,453

setdiff(B, A)

That's great! I solve one problem but I have the last one problem, I need to get a derivative with notation like the following:

I have a position vector and I need to derive and get vector speed, but I need to appear it notation for the first derivative, second derivative, etc.

how can I do it?

thanks.

Walter Roberson
on 19 Sep 2018

- 30 questions asked
- 40,358 answers
- 15,346 accepted answers
- reputation: 79,453

You can use pretty(), or you can use LiveScript .

I try to use pretty () but matlab show a error.

but this is the problema I fill in with this ecuation.

I want to get the first ecuation on next picture. But If it were possible to obtain it with the notation of the second equation, it would be better

Walter Roberson
on 20 Sep 2018

- 30 questions asked
- 40,358 answers
- 15,346 accepted answers
- reputation: 79,453

BL = latex(B)

But then you would have to display the latex stored in BL somehow.

You cannot get the graphical format you want to store into a variable. That format is a graphical format that is not how MATLAB represents symbolic expressions internally. You can render into latex like I show, but the result is a character vector that cannot be operated on symbolically.

Hello.

How can I get the shorter from a ecuation?

I try to use "simplify" but I don't get the shorter form.

I found "simple" but I don't know how can I use it.

I get this error.

Thank you very much

Walter Roberson
on 14 Oct 2018

- 30 questions asked
- 40,358 answers
- 15,346 accepted answers
- reputation: 79,453

- 30 questions asked
- 40,358 answers
- 15,346 accepted answers
- reputation: 79,453

What is in your vel variable, and what shorter form are you expecting?

If you are hoping for trig identities to be used to create a simpler expression, then use rewrite() and simplify()

I try to simplifly this ecuation but when I use "simplify" Matlab give me the same result.

I simplified in my notebook, I got this result.

But I used trigonometric identities to simplify the ecuation

- 30 questions asked
- 40,358 answers
- 15,346 accepted answers
- reputation: 79,453

Nope. You have made a mistake somewhere, or else your notebook is wrong.

>> vel2

vel2 =

(y2*sin(t1) - y2*cos(t1) + d2*w1*cos(t1) + d2*w1*sin(t1))^2

>> subs(vel2,[w1,y2,d2],[3,5,7])

ans =

(16*cos(t1) + 26*sin(t1))^2

>> subs(d2^2*w1^2+y2^2,[w1,y2,d2],[3,5,7])

ans =

466

These are not equivalent.

I want to simplify with variables not with numbers, this is my notebook.

In picture we can see "P" is a position vector, we need to derive to get speed vector "V" and we need to raise the square vector and simplify.

It is worth mentioning that the variables are replaced as follows between Matlab code and notebook

thanks

Walter Roberson
on 15 Oct 2018

- 30 questions asked
- 40,358 answers
- 15,346 accepted answers
- reputation: 79,453

"I want to simplify with variables not with numbers, this is my notebook."

If you substitute specific numeric values into both forms, and you do not get the same result, then one of the two forms must be wrong.

ok I am goin to check my notebook but could you help me how to displayed some ecuation in Latex form in an axes?

I have looked for information and I have found this code but Matlab doesn't do anything

- 30 questions asked
- 40,358 answers
- 15,346 accepted answers
- reputation: 79,453

s = ['$$', latex(vel2), '$$'];

text(0.2, 0.5, s, 'Interpreter', 'latex')

looks okay to me.

- 30 questions asked
- 40,358 answers
- 15,346 accepted answers
- reputation: 79,453

It is a bit difficult to interpret your notebook, as you go from column vector to v^2 equation without intermediate form showing how v was derived.

Your v^2 appears to be calculated by squaring the individual components of the column vector and summing those.

Your vel2 term, on the other hand, is calculated by summing the elements in the column vector and squaring the result. Thus, vel2 has cross-product terms in it where v^2 does not.

I can't show ecuation, I modified the code like this. In where part of yur code I can send the result to axes1?.

if true

s = ['$$', latex(vel), '$$'];

axes(handles.axes1)

cla

text(0.2, 0.5, s, 'Interpreter', 'latex')

end

I was cheking my notebook and I found two things that I forget tell you, firstly "t1" and "d2" are variables in time, "d1" is variable but for derivate is constant, don't worry for that I already fix the code with "if" for that. Second thing I have "P" then I derive and I get "V", in this vector I square the terms and then add them after I simplify the ecuation with trigonometric identities and I get the result as you can see in the notebook.

this is my code.

if true

aux2 = [aux5; aux6; aux7];

vel = sum(aux2);

vel = expand(vel);

s = ['$$', latex(vel), '$$'];

axes(handles.axes1)

cla

text(0.2, 0.5, s, 'Interpreter', 'latex')

vel2 = vel^2

vel2 = simplify (vel2)

end

Walter Roberson
on 16 Oct 2018

- 30 questions asked
- 40,358 answers
- 15,346 accepted answers
- reputation: 79,453

if true

function Resolver4_Callback(hObject, eventdata, handles)

syms m g rt w1 w2 w3 y1 y2 y3

global Px Py Pz gdl

aux1 = Px + Py + Pz;

A =(get(handles.tabla1,'Data'));

if gdl == 1

B = cell2sym( [A(1,1)]);

aux3 = B*1;

end

if gdl == 2

B = cell2sym( [A(1,1), A(2,1)]);

aux3 = B(1,1) * B(1,2)

end

if gdl == 3

B = cell2sym ([A(1,1), A(2,1), A(3,1)])

aux3 = B(1,1) * B(1,2) * B(1,3);

end

if aux3 == 0

errordlg('Ingrese las variables correspondientes por articulaciĆ³n.', 'Error');

else

C = symvar(aux1)

D = setdiff(C,B)

F = setdiff(C,D)

aux2 = gradient(aux1,F)

if gdl == 1

art1 = str2double(get(handles.arti1,'String'));

if art1 == 2

vel = aux2*y1;

else

vel = aux2*w1;

end

vel = expand(vel);

Mc = arrayfun(@char, vel, 'uniform', 0).';

maxlen = max(cellfun(@length, Mc(:)));

EL1 = sprintf('%%%ds, ', maxlen);

fmt = repmat([repmat(EL1, 1, size(vel,2)-1), '%s\n'], 1, size(vel,1));

outstr = regexp(sprintf(fmt, Mc{:}),'\n', 'split');

set(handles.velocidad, 'String', outstr, 'fontname', 'fixed');

end

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);

Mc = arrayfun(@char, vel, 'uniform', 0).';

maxlen = max(cellfun(@length, Mc(:)));

EL1 = sprintf('%%%ds, ', maxlen);

fmt = repmat([repmat(EL1, 1, size(vel,2)-1), '%s\n'], 1, size(vel,1));

outstr = regexp(sprintf(fmt, Mc{:}),'\n', 'split');

set(handles.velocidad, 'String', outstr, 'fontname', 'fixed');

end

if gdl == 3

art1 = str2double(get(handles.arti1,'String'));

art2 = str2double(get(handles.arti2,'String'));

art3 = str2double(get(handles.arti3,'String'));

if art1 == 2

aux5 = aux2(3,1)*y1;

else

aux5 = aux2(3,1)*w1;

end

if art2 == 2

aux6 = aux2(1,1)*y2;

else

aux6 = aux2(1,1)*w2;

end

if art3 == 2

aux7 = aux2(2,1)*y3;

else

aux7 = aux2(2,1)*w3;

end

aux2 = [aux5; aux6; aux7];

vel = sum(aux2);

vel = expand(vel);

Mc = arrayfun(@char, vel, 'uniform', 0).';

## 0 Comments

Sign in to comment.