Plots for second order control system in the same graph
5 次查看(过去 30 天)
显示 更早的评论
I'm been trying to graph this equation without success.I keep getting an error message that says:Warning: Imaginary parts of complex X and/or Y arguments ignored.
Note: input is in radiant.
Here is my code:
% Exersice 11
x = input('Please enter vector x in degree: ');
z = [0.1 0.2 0.4 0.7 0.9];
y1 = 1-1/sqrt(1-z(1,1).^2).*exp(-z(1,1).*x).*sin(sqrt(1-z(1,1).^2)).*x+acos(x);
y2 = 1-1/sqrt(1-z(1,2).^2).*exp(-z(1,2).*x).*sin(sqrt(1-z(1,2).^2)).*x+acos(x);
y3 = 1-1/sqrt(1-z(1,3).^2).*exp(-z(1,3).*x).*sin(sqrt(1-z(1,3).^2)).*x+acos(x);
y4 = 1-1/sqrt(1-z(1,4).^2).*exp(-z(1,4).*x).*sin(sqrt(1-z(1,4).^2)).*x+acos(x);
y5 = 1-1/sqrt(1-z(1,5).^2).*exp(-z(1,5).*x).*sin(sqrt(1-z(1,5).^2)).*x+acos(x);
plot(x,y1,x,y2,x,y3,x,y4,x,y5, 'm'), xlabel('x in radiands'), ylabel('y(x)') ,title('1-1/{\surd}(1-\zeta^2)e^-^\zeta^xsin{\surd}(1-\zeta^2)x+cos^-^1(x)'), grid, legend('\zeta = 0.1','\zeta = 0.2','\zeta = 0.4','\zeta = 0.7','\zeta = 0.9')
采纳的回答
Paul
2014-3-30
编辑:Paul
2014-3-30
Two things are wrong. One is the parenthesis before .x which should be on the end. The second is the acos(x) which should be acos(z(...)). Also it doesnt make sense that you ask x in degrees while it should be radians:
x = input('Please enter vector x in radians: ');
z = [0.1 0.2 0.4 0.7 0.9];
y1 = 1-(1/sqrt(1-z(1,1).^2)).*exp(-z(1,1).*x).*sin(sqrt(1-z(1,1).^2).*x+acos(z(1,1)));
y2 = 1-1/sqrt(1-z(1,2).^2).*exp(-z(1,2).*x).*sin(sqrt(1-z(1,2).^2).*x+acos(z(1,2)));
y3 = 1-1/sqrt(1-z(1,3).^2).*exp(-z(1,3).*x).*sin(sqrt(1-z(1,3).^2).*x+acos(z(1,3)));
y4 = 1-1/sqrt(1-z(1,4).^2).*exp(-z(1,4).*x).*sin(sqrt(1-z(1,4).^2).*x+acos(z(1,4)));
y5 = 1-1/sqrt(1-z(1,5).^2).*exp(-z(1,5).*x).*sin(sqrt(1-z(1,5).^2).*x+acos(z(1,5)));
figure;
plot(x,y1,x,y2,x,y3,x,y4,x,y5, 'm'), xlabel('x in radiands'), ylabel('y(x)') ,title('1-1/{\surd}(1-\zeta^2)e^-^\zeta^xsin{\surd}(1-\zeta^2)x+cos^-^1(x)'), grid, legend('\zeta = 0.1','\zeta = 0.2','\zeta = 0.4','\zeta = 0.7','\zeta = 0.9')
It would also be easier to just use z(2) instead of z(1,2) etc. and using a for loop like Mischa suggested would save you the copy paste code.
0 个评论
更多回答(1 个)
Mischa Kim
2014-3-26
编辑:Mischa Kim
2014-3-26
Carlos, check out
function myDE()
prompt = {'xmin:','xmax:'};
name = 'Input x-range';
numlines = 1;
xlimits = inputdlg(prompt,name,numlines);
N = 100;
x = linspace(str2num(xlimits{1}),str2num(xlimits{2}),N);
z = [0.1 0.2 0.4 0.7 0.9];
hold all
for ii = 1:numel(z)
y = 1 - (1/sqrt(1-z(ii)^2))*exp(-z(ii)*x).*sin(sqrt(1-z(ii)^2)*x...
+ acos(z(ii)));
plot(x,y)
end
end
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Assembly 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!