Switch conditions or formula in a continuous data
2 views (last 30 days)
Show older comments
Hello Expert, i'm chris and i'm really new in using MATLAB. I have a problem to make a continuous graphic with a different conditions. the condition is in a formula or maybe a function. first, i have two boundary conditions and the value of the boundary condition is calculated by a formula. then i have two boundary conditions, let's say it is X1 and X2. then for the data(for an example the data is the length of a beam) between 0 to X1 are the first condition. then for the data between X1 to X2 are the second condition and the data that is larger than X2 are the third conditions. and here is the script that i wrote.
A=input('A= ');
B=input('B= ');
C=input('C= ');
D=input('D= ');
E=input('E= ');
F=input('F= ');
G=input('G= ');
H=input('H= ');
I=input('I= ');
J=input('J= ');
%start calculation
X1=A+B;
X2=C+D;
L=1:1000; %it's the length data
y=zeros(size(L))
idx=L<X1;
y(idx) = E*F;
idx = L>=X1 & L<=X2
y(idx) = (G-H)*((L-X1)/(X2-X1));
idx = L>X2;
y(idx) = ((I/J)^2)*(H/L);
plot(L,y)
the script above didn't give me the conditions that i wanted. so, i need a help for solving this problem
Thank you in Advance
0 Comments
Accepted Answer
Andrei Bobrov
on 31 Dec 2011
try this is code
idx1=L<X1;
y(idx1) = E*F;
idx2 = L>=X1 & L<=X2;
y(idx2) = (G-H)*((L(idx2)-X1)/(X2-X1));
idx3 = L>X2;
y(idx3) = ((I/J)^2)*(H./L(idx3));
plot(L,y);
variant
[a,a] = histc(L,[-inf,X1,X2,inf]);
z = {@(x)E*F,@(x)(G-H)*((x-X1)/(X2-X1)),@(x)(I/J)^2*H./x};
out = arrayfun(@(x)z{x}(L(a==x)),1:3,'un',0);
y = [out{:}];
ADD [ 13:26(UTC+4) 01.01.2012]
Mn=zeros(size(Lb));
FZ = Fy*Zx;
Mn(Lb<=Lp)= FZ;
idx2=Lb>Lp & Lb<=Lr;
Mn(idx2)=Cb*(FZ - (FZ-Mr)*(Lb(idx2)-Lp)/(Lr-Lp));
idx3=Lb>Lr;
p1 = pi./Lb(idx3);
Mn(idx3)=Cb*p1.*sqrt(E*Iy*G*J+(E*p1).^2*Iy*Iw);
variant 2
Mn=zeros(size(Lb));
[a,a] = histc(Lb,[-inf,Lp,Lr,inf]);
FZ = Fy*Zx;
z = {@(x)FZ*ones(size(x)),...
@(x)Cb*(Fy*Zx-(FZ-Mr)*(x-Lp)/(Lr-Lp)),...
@(x)Cb*pi./x.*sqrt(E*Iy*G*J+(pi*E./x).^2*Iy*Iw)};
out = arrayfun(@(x)z{x}(Lb(a==x)),1:max(a),'un',0);
y = [out{:}];
2 Comments
More Answers (0)
See Also
Categories
Find more on Numerical Integration and Differential Equations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!