Help to draw a graph of a function.
2 ビュー (過去 30 日間)
古いコメントを表示
zekeriya özkan
2021 年 5 月 27 日
編集済み: Sulaymon Eshkabilov
2021 年 5 月 30 日
There was two mistakes. I wrote in a true way. And I want anyone to help me. I studied to draw the graph of function given at the bottom of page. But my drawing is not the same as the expected figure. Please, help how can i correct my MATLAB codes.
clc; clear; clear all;
a=1;
d0=2;
v0=2;
nu=sqrt(2.5);
sumxx=[];
k=100;
for endp=1:k
T=linspace(endp-1,endp,101);
sumx=d0.*cos(nu.*T)+(v0./nu).*sin(nu.*T)+((a.*d0)./nu.^2).*(1-cos(nu.*T));
for n=0:endp-1
K=omega(a,n,nu,v0,d0).*(1-cos(nu.*(T-(n+1))));
sumx=sumx+(a./nu.^2).*K;
end
% sumx=sumx.*x0;
sumxx=[sumxx,sumx];
clear sumx
end
tt=linspace(0,k,k*101);
plot(tt,sumxx)
grid on
hold on
omega.m function is given below;
function w=omega(a,n,nu,v0,d0)
M=[(1-a./(nu.^2)).*cos(nu)+a./(nu.^2) sin(nu)./nu;-nu.*(1-a./(nu.^2)).*sin(nu) cos(nu)];
w=([(1-a./(nu.^2)).*cos(nu)+a./(nu.^2) sin(nu)./nu]*M-[1 0])*(M.^n)*[d0;v0];
end
My function is given like that;

and the expected figure is given like that

5 件のコメント
Walter Roberson
2021 年 5 月 28 日
The requirements are to plot over 0 <= t < m, but the piecewise definition only gives an expression for m <= t < m+1 so we do not know anything about the function over the interval that it is to be plotted over.
採用された回答
Sulaymon Eshkabilov
2021 年 5 月 28 日
Hi,
(1) There are some inconsistencies with the initial conditions. As given the formulations can never produce some ripples such uneven points (some uncertainties/noises are present). Since the given formulations are composed of sines and cosines, and thus, the resulting response of the system has to be a smooth plot.
(2) The shown plot is decaying process (reponse) that shows that there is significant damping > 1. With the given data, it is not a decaying process.
In implementation, some parts of the code is not correctly embeded. Here is a corrected code:
...
k=1000;
%for endp=1:k
T=linspace(0,25, 1001);
sumx=d0.*cos(nu.*T)+(v0./nu).*sin(nu.*T)+((a.*d0)./nu.^2).*(1-cos(nu.*T));
for n=0:1000
K=omega(a,n,nu,v0,d0).*(1-cos(nu.*(T-(n))));
sumx=sumx+(a./nu.^2).*K;
end
% sumx=sumx.*x0;
sumxx=[sumxx,sumx];
clear sumx
%end
...
Good luck.
3 件のコメント
Walter Roberson
2021 年 5 月 30 日
Unfortunately we cannot scroll back the image of the command window to see what MATLAB thinks the error is .
その他の回答 (1 件)
Sulaymon Eshkabilov
2021 年 5 月 30 日
Hi,
Here is the complete code:
clc; clearvars;
a=1;
d0=2;
v0=2;
nu=sqrt(2.5);
sumxx=[];
k=1000;
T=linspace(0,25, 1001);
sumx=d0.*cos(nu.*T)+(v0./nu).*sin(nu.*T)+((a.*d0)./nu.^2).*(1-cos(nu.*T));
for n=0:1000
K=omega(a,n,nu,v0,d0).*(1-cos(nu.*(T-(n))));
sumx=sumx+(a./nu.^2).*K;
end
SX=sumx;
plot(T,SX)
grid on
hold on
function w=omega(a,n,nu,v0,d0)
M=[(1-a./(nu.^2)).*cos(nu)+a./(nu.^2) sin(nu)./nu;-nu.*(1-a./(nu.^2)).*sin(nu) cos(nu)];
w=([(1-a./(nu.^2)).*cos(nu)+a./(nu.^2) sin(nu)./nu]*M-[1 0])*(M.^n)*[d0;v0];
end
2 件のコメント
Sulaymon Eshkabilov
2021 年 5 月 30 日
編集済み: Sulaymon Eshkabilov
2021 年 5 月 30 日
You are MOST Welcome - Ag'a! from Uzbekistan.
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!