If I use multi funcions with syms variable, How can I get track min value among that funcions?

clear; clc; close all;
syms seta
Rx1= cos(seta)
Rx2= sin(seta)
If I set Rx1, Rx2 funcion like that, How can I get the graph with min value among Rx1, Rx2?
If I use discrete value, I can use like this
xmin=min([R1(x(:)');R2(x(:)');])
plot(x,xmin,'.-');
but, In this case I using Symbolic Math Toolbox, I don't know how I can make it works with syms variable...

 Akzeptierte Antwort

You need to use something like
Min = @(tworows) arrayfun( @(colidx) piecewise(tworows(1,colidx) <= tworows(2,colidx), tworows(1,colidx), tworows(2,colidx)), 1:size(tworows,2);
The code could be simplified if you were willing to use R1 and R2 as separate arguments instead of putting them together in one array.

7 Kommentare

clear; clc; close all;
syms seta
gamma = 1;
Rx_ = 1;
Ry_ = Rx_*gamma;
% 등가 정적 적용
gamma = 1;
Rx1= matlabFunction(( cos(seta)-0.3*sin(seta) )*Rx_ ); Rx(1)= "(cos(seta)-0.3 * sin(seta)) * Rx_" ;
Rx2= matlabFunction(( cos(seta)+0.3*sin(seta) )*Rx_); Rx(2)= "(cos(seta)+0.3 * sin(seta)) * Rx_";
Rx3= matlabFunction(( 0.3*cos(seta)-sin(seta) )*Rx_); Rx(3)= "(0.3*cos(seta)-sin(seta)) * Rx_";
Rx4= matlabFunction(( -0.3*cos(seta)-sin(seta) )*Rx_); Rx(4)= "(-0.3*cos(seta)-sin(seta)) * Rx_";
Ry1= (0.3*cos(seta) + sin(seta) )*Ry_; Ry(1)= "(0.3*cos(seta) + sin(seta)) * Ry_";
Ry2= (-0.3*cos(seta) + sin(seta) )*Ry_; Ry(2)= "(-0.3*cos(seta) + sin(seta)) * Ry_";
Ry3= (cos(seta) + 0.3*sin(seta) )*Ry_; Ry(3)= "(cos(seta) + 0.3*sin(seta)) * Ry_";
Ry4= (cos(seta) - 0.3*sin(seta) )*Ry_; Ry(4)= "(cos(seta) - 0.3*sin(seta)) * Ry_";
N=4;
for ii=1:N
temp=['RR',num2str(ii),'=matlabFunction(','Rx',num2str(ii),'+Ry',num2str(ii),');'];
eval(temp);
minx=['a',num2str(ii),'=fminbnd(RR',num2str(ii),',0,2*pi);'];
maxx=['b',num2str(ii),'=fminbnd(@(seta)-RR',num2str(ii),'(seta),0,2*pi);'];
eval(minx);
eval(maxx);
end
for ii=1:N
subplot(4,1,ii)
gx=['g',num2str(ii),'x=fplot(Rx',num2str(ii),',[0 2*pi],''--''); hold on'];
gy=['g',num2str(ii),'y=fplot(Ry',num2str(ii),',[0 2*pi]); hold on'];
g1=['g',num2str(ii),'=fplot(RR',num2str(ii),',[0 2*pi]); hold on'];
min=['min=plot(a',num2str(ii),',RR',num2str(ii), ' (a',num2str(ii),'),''*''); hold on '];
max=['max=plot(b',num2str(ii),',RR',num2str(ii), ' (b',num2str(ii),'),''*''); hold on '];
a= ['a11=a',num2str(ii),';'];
b= ['b11=b',num2str(ii),';'];
RR= ['RR11=RR',num2str(ii),';'];
eval(gx); eval(gy); eval(g1); eval(min); eval(max); eval(a); eval(b); eval(RR);
a="(" + num2str(round(a11/pi,2))+"pi [" + num2str(round(a11/pi*180,2))+"\circ]";
a_= " , " + num2str(round(RR11(a11),2))+")";
a= a + a_;
b="(" + num2str(round(b11/pi,2))+"pi [" + num2str(round(b11/pi*180,2))+"\circ]";
b_= " , " + num2str(round(RR11(b11),2))+")";
b= b + b_;
xticks([0 0.5*pi pi 1.5*pi 2*pi])
xticklabels({'0','0.5\pi','\pi','1.5\pi','2\pi'})
legend('x축','y축',"단순합",a,b,'location','best')
title(Rx(ii)+" + "+Ry(ii),'interpreter','none');
end
I'm sorry I can't understand. here is my code then how I can use that if I trace min value graph within RR1~RR4.
Your use of eval() for dynamic variable names is... distracting... Sufficiently distracting that I would not bother to try to debug that code. I advise you to scrap it and rewrite it without using dynamic variable names.
clear; clc; close all;
syms seta
gamma = 1;
Rx_ = 1;
Ry_ = Rx_*gamma;
% 등가 정적 적용
gamma = 1;
Rx1= matlabFunction(( cos(seta)-0.3*sin(seta) )*Rx_ ); Rx(1)= "(cos(seta)-0.3 * sin(seta)) * Rx_" ;
Rx2= matlabFunction(( cos(seta)+0.3*sin(seta) )*Rx_); Rx(2)= "(cos(seta)+0.3 * sin(seta)) * Rx_";
Rx3= matlabFunction(( 0.3*cos(seta)-sin(seta) )*Rx_); Rx(3)= "(0.3*cos(seta)-sin(seta)) * Rx_";
Rx4= matlabFunction(( -0.3*cos(seta)-sin(seta) )*Rx_); Rx(4)= "(-0.3*cos(seta)-sin(seta)) * Rx_";
Ry1= (0.3*cos(seta) + sin(seta) )*Ry_; Ry(1)= "(0.3*cos(seta) + sin(seta)) * Ry_";
Ry2= (-0.3*cos(seta) + sin(seta) )*Ry_; Ry(2)= "(-0.3*cos(seta) + sin(seta)) * Ry_";
Ry3= (cos(seta) + 0.3*sin(seta) )*Ry_; Ry(3)= "(cos(seta) + 0.3*sin(seta)) * Ry_";
Ry4= (cos(seta) - 0.3*sin(seta) )*Ry_; Ry(4)= "(cos(seta) - 0.3*sin(seta)) * Ry_";
RR1=@(seta)cos(seta).*(1.3e+1./1.0e+1)+sin(seta).*(7.0./1.0e+1);
RR2=@(seta)cos(seta).*(7.0./1.0e+1)+sin(seta).*(1.3e+1./1.0e+1);
RR3=@(seta)cos(seta).*(1.3e+1./1.0e+1)-sin(seta).*(7.0./1.0e+1);
RR4=@(seta)cos(seta).*(1.3e+1./1.0e+1)-sin(seta).*(7.0./1.0e+1);
a1=fminbnd(RR1,0,2*pi);
b1=fminbnd(@(seta)-RR1(seta),0,2*pi);
a2=fminbnd(RR2,0,2*pi);
b2=fminbnd(@(seta)-RR2(seta),0,2*pi);
a3=fminbnd(RR3,0,2*pi);
b3=fminbnd(@(seta)-RR3(seta),0,2*pi);
a4=fminbnd(RR4,0,2*pi);
b4=fminbnd(@(seta)-RR4(seta),0,2*pi);
% % 위에 반복문의 기준이 된 코드::
subplot(4,1,1);
g1x=fplot(Rx1,[0 2*pi]); hold on
g1y=fplot(Ry1,[0 2*pi]); hold on
g1=fplot(RR1,[0 2*pi]);
min=plot(a1,RR1(a1),'*');
max=plot(b1,RR1(b1),'*');
a="(" + num2str(round(a1/pi,2))+"pi [" + num2str(round(a1/pi*180,2))+"\circ]";
a_= " , " + num2str(round(RR1(a1),2))+")";
a= a + a_;
b="(" + num2str(round(b1/pi,2))+"pi [" + num2str(round(b1/pi*180,2))+"\circ]";
b_= " , " + num2str(round(RR1(b1),2))+")";
b= b + b_;
xticks([0 0.5*pi pi 1.5*pi 2*pi])
xticklabels({'0','0.5\pi','\pi','1.5\pi','2\pi'})
legend('x축','y축',"단순합",a,b,'location','best')
subplot(4,1,2);
g1x=fplot(Rx2,[0 2*pi]); hold on
g1y=fplot(Ry2,[0 2*pi]); hold on
g1=fplot(RR2,[0 2*pi]);
min=plot(a2,RR2(a2),'*');
max=plot(b2,RR2(b2),'*');
a="(" + num2str(round(a2/pi,2))+"pi [" + num2str(round(a2/pi*180,2))+"\circ]";
a_= " , " + num2str(round(RR2(a2),2))+")";
a= a + a_;
b="(" + num2str(round(b2/pi,2))+"pi [" + num2str(round(b2/pi*180,2))+"\circ]";
b_= " , " + num2str(round(RR2(b2),2))+")";
b= b + b_;
xticks([0 0.5*pi pi 1.5*pi 2*pi])
xticklabels({'0','0.5\pi','\pi','1.5\pi','2\pi'})
legend('x축','y축',"단순합",a,b,'location','best')
ㅠㅠ I'm so sorry to bother you. here is my rewiting code.
MIN2 = @(v1, v2) piecewise(v1 <= v2, v1, v2);
MIN4 = @(v1, v2, v3, v4) MIN2(MIN2(v1,v2),MIN2(v3,v4));
RR1234 = MIN4(R1,R2,R3,R4);
fplot(RR1234, [0 2*pi])
Thanks, I think almost done, but I had error message
Undefined operator '<=' for input arguments of type 'function_handle'.
close all;
syms seta
gamma = 1;
Rx_ = 1;
Ry_ = Rx_*gamma;
% 등가 정적 적용
gamma = 1;
Rx1= matlabFunction(( cos(seta)-0.3*sin(seta) )*Rx_ ); Rx(1)= "(cos(seta)-0.3 * sin(seta)) * Rx_" ;
Rx2= matlabFunction(( cos(seta)+0.3*sin(seta) )*Rx_); Rx(2)= "(cos(seta)+0.3 * sin(seta)) * Rx_";
Rx3= matlabFunction(( 0.3*cos(seta)-sin(seta) )*Rx_); Rx(3)= "(0.3*cos(seta)-sin(seta)) * Rx_";
Rx4= matlabFunction(( -0.3*cos(seta)-sin(seta) )*Rx_); Rx(4)= "(-0.3*cos(seta)-sin(seta)) * Rx_";
Ry1= (0.3*cos(seta) + sin(seta) )*Ry_; Ry(1)= "(0.3*cos(seta) + sin(seta)) * Ry_";
Ry2= (-0.3*cos(seta) + sin(seta) )*Ry_; Ry(2)= "(-0.3*cos(seta) + sin(seta)) * Ry_";
Ry3= (cos(seta) + 0.3*sin(seta) )*Ry_; Ry(3)= "(cos(seta) + 0.3*sin(seta)) * Ry_";
Ry4= (cos(seta) - 0.3*sin(seta) )*Ry_; Ry(4)= "(cos(seta) - 0.3*sin(seta)) * Ry_";
RR1=@(seta)cos(seta).*(1.3e+1./1.0e+1)+sin(seta).*(7.0./1.0e+1);
RR2=@(seta)cos(seta).*(7.0./1.0e+1)+sin(seta).*(1.3e+1./1.0e+1);
RR3=@(seta)cos(seta).*(1.3e+1./1.0e+1)-sin(seta).*(7.0./1.0e+1);
RR4=@(seta)cos(seta).*(1.3e+1./1.0e+1)-sin(seta).*(7.0./1.0e+1);
a1=fminbnd(RR1,0,2*pi);
b1=fminbnd(@(seta)-RR1(seta),0,2*pi);
a2=fminbnd(RR2,0,2*pi);
b2=fminbnd(@(seta)-RR2(seta),0,2*pi);
a3=fminbnd(RR3,0,2*pi);
b3=fminbnd(@(seta)-RR3(seta),0,2*pi);
a4=fminbnd(RR4,0,2*pi);
b4=fminbnd(@(seta)-RR4(seta),0,2*pi);
% % 위에 반복문의 기준이 된 코드::
subplot(4,1,1);
fplot(Rx1,[0 2*pi]); hold on
fplot(Ry1,[0 2*pi]); hold on
fplot(RR1,[0 2*pi]);
plot(a1,RR1(a1),'*');
plot(b1,RR1(b1),'*');
a="(" + num2str(round(a1/pi,2))+"pi [" + num2str(round(a1/pi*180,2))+"\circ]";
a_= " , " + num2str(round(RR1(a1),2))+")";
a= a + a_;
b="(" + num2str(round(b1/pi,2))+"pi [" + num2str(round(b1/pi*180,2))+"\circ]";
b_= " , " + num2str(round(RR1(b1),2))+")";
b= b + b_;
xticks([0 0.5*pi pi 1.5*pi 2*pi])
xticklabels({'0','0.5\pi','\pi','1.5\pi','2\pi'})
legend('x축','y축',"단순합",a,b,'location','best')
subplot(4,1,2);
fplot(Rx2,[0 2*pi]); hold on
fplot(Ry2,[0 2*pi]); hold on
fplot(RR2,[0 2*pi]);
plot(a2,RR2(a2),'*');
plot(b2,RR2(b2),'*');
a="(" + num2str(round(a2/pi,2))+"pi [" + num2str(round(a2/pi*180,2))+"\circ]";
a_= " , " + num2str(round(RR2(a2),2))+")";
a= a + a_;
b="(" + num2str(round(b2/pi,2))+"pi [" + num2str(round(b2/pi*180,2))+"\circ]";
b_= " , " + num2str(round(RR2(b2),2))+")";
b= b + b_;
xticks([0 0.5*pi pi 1.5*pi 2*pi])
xticklabels({'0','0.5\pi','\pi','1.5\pi','2\pi'})
legend('x축','y축',"단순합",a,b,'location','best')
MIN2 = @(v1, v2) piecewise(v1 <= v2, v1, v2);
MIN4 = @(v1, v2, v3, v4) MIN2(MIN2(v1,v2),MIN2(v3,v4));
R1 = RR1(seta);
R2 = RR2(seta);
R3 = RR3(seta);
R4 = RR4(seta);
RR1234 = MIN4(R1,R2,R3,R4);
figure
fplot(RR1234, [0 2*pi])
WOW wonderful. amazing. thank you very much

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Produkte

Version

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by