symbolic variable

2 visualizzazioni (ultimi 30 giorni)
Hassan
Hassan il 8 Mar 2011
'G' is a function of symbolic variable of 'b' the solve for b gives d=solve(G) a symbolic n*1 matrix but I'm not able to find the min or max even >(greater than sign)of this matrix. Matlab shows this following error Undefined function or method 'gt' for input arguments of type 'sym'.

Risposta accettata

Walter Roberson
Walter Roberson il 8 Mar 2011
re=solve(GG); will return symbolic numbers. You need to apply double() to the symbolic numbers to convert them to floating point numbers.

Più risposte (1)

Mike
Mike il 8 Mar 2011
Since you haven't given explicit code one, can only speculate on the contents of your matrix d. However, here is an explicit example that I believe illustrates the issue. Say you have
>> syms a b c x;
>> results=solve('a*x^2 + b*x + c')
This gives
results =
-(b + (b^2 - 4*a*c)^(1/2))/(2*a)
-(b - (b^2 - 4*a*c)^(1/2))/(2*a)
Lets try to find the max of that matrix.
>> max(results)
??? Undefined function or method 'max' for input arguments of type 'sym'.
If you think about it, this should not surprise you since we do not know the values of the symbolic variables a,b and c and the results of max will depend on these values. For example
a=1;b=1;c=1
>> y=subs(results)
y =
-0.5000 - 0.8660i
-0.5000 + 0.8660i
>> max(y)
ans =
-0.5000 + 0.8660i
So for a=1;b=1;c=1, the second element of results is the maximum. However, for a=-1;b=1;c=1, the first element of results is the maximum:
>> a=-1;b=1;c=1;
>> y=subs(results)
y =
1.6180
-0.6180
>> max(y)
ans =
1.6180
Hope this helps, Mike
  1 Commento
Hassan
Hassan il 8 Mar 2011
Dear Mike
x1=sym('x1','real');
x2=sym('x2','real');
x3=sym('x3','real');
z1=sym('z1','real');
z2=sym('z2','real');
z3=sym('z3','real');
b=sym('b','real');
alpha=zeros(1,3);
m=[95,50,4000];
sig=[10,2.5,1000];
r=[-(1/3)^.5,(1/3)^.5,-(1/3)^.5];
digits(4)
x=[x1,x2,x3];
z=[z1,z2,z3];
for i=1:3;
x(1,i)=sig(1,i).*z(1,i)+m(1,i);
end
g=1.25*x(1,1).*x(1,2)-x(1,3)./2;
G=vpa(expand(subs(g)));
grad1=diff(G,'z1');
grad2=diff(G,'z2');
grad3=diff(G,'z3');
bb=0;
for i=1:10;
z1=alpha(1,1).*bb;
z2=alpha(1,2).*bb;
z3=alpha(1,3).*bb;
grad=[subs(grad1),subs(grad2),subs(grad3)];
k=(grad*grad')^.5;
for j=1:3;
alpha(1,j)=grad(1,j)/k;
end
z1=-alpha(1,1).*b;
z2=-alpha(1,2).*b;
z3=-alpha(1,3).*b;
GG=subs(G);
re=solve(GG);
a=max(size(b));
for k=1:a;
if re(k,1)>re(1,1);
y=re(1,1);
else
y=re(k,1);
end
end
end
this is my m.file

Accedi per commentare.

Categorie

Scopri di più su Symbolic Math Toolbox in Help Center e File Exchange

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by