user function and plot
2 ビュー (過去 30 日間)
古いコメントを表示
function [x1,x2]=distance_plot(W)
prompt1=('input value of W(N) = ') %W값 입력받기
prompt2=('input value of d(m) = ') %d값 입력받기
W=input(prompt1);
d=input(prompt2);
k1=104; %단위:N/m
k2=1.5*10^4; %단위:N/m
W0=linspace(0,W,1000);
x=0;
if x<d
x1=W/k1;
else x>=d
x2=(W+2*k2*d)/(k1+2*k2);
end
if x<d
x=linspace(0,d,1000);
plot(x1,W0)
xlabel('x1')
ylabel('W')
grid
else x>=d
x=linspace(0,d,1000);
plot(x2,W0)
xlabel('x2')
ylabel('W')
grid
end
(Don't care about the comments)
hello
i made a code(used defined function).
i thought about drawing a graph with a specified range according to the value of 'W' and 'd'.
there is no error code but graph didn't appear in the figure window.
Is it wrong to put the input value 'W' and 'd' directly into the ( W0=linspace(0,W,1000); ) and ( x=linspace(0,d,1000); )?
any other wrong?
thanks!
1 件のコメント
Rik
2022 年 11 月 17 日
You're already writing a function, so why not have W and d both as input arguments? You're currently overwriting your input argument W in that input statement.
採用された回答
VBBV
2022 年 11 月 17 日
May be this change, with regards to returning output variables x1 and x2 since function is not returning both variables as written
[x1 x2] = distance_plot
function [x1,x2]=distance_plot % empty or no argument since inputs for W and d are fed after function call
W = 10; %input value for W e.g
d = 4; % input value for d e.g
k1=104; %단위:N/m
k2=1.5*10^4; %단위:N/m
W0=linspace(0,W,1000);
x=0;
if x<d % common condition
x1=W/k1;
x2=linspace(0,d,1000);
plot(x2,W0)
xlabel('x1')
ylabel('W')
grid
else x>=d % common condition
x2=(W+2*k2*d)/(k1+2*k2);
x1=linspace(0,d,1000);
plot(x1,W0)
xlabel('x2')
ylabel('W')
grid
end
end
0 件のコメント
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Graphics Performance についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!