# I can't figure out how to define X in a piecewise function to create a Bending Moment Diagram

3 ビュー (過去 30 日間)
Ezekiel Lawrence 2021 年 9 月 20 日
コメント済み: Ezekiel Lawrence 2021 年 9 月 20 日
I missed this lecture and am trying to figure it out so it doesn't bite me going forward.
My professor supplied us with this script which is supposed to display the M(x) piecewise, "momentfunctionarray.mlx" which reads as follows:
function y = momentfunctionarray(x)
len = length(x);
for i = 1:1:len
if x(i) >= 0 && x(i) < 3
y(i) = 265*x(i)-5.56*x(i)^3;
elseif x(i) >= 3 && x(i) < 6
y(i) = -50*x(i)^2 + 415*x(i) - 150;
elseif x(i) >= 6 && x(i) < 10
y(i) = -185*x(i) + 1650;
elseif x(i) >= 10 && x(i) <= 12
y(i) = 100*x(i) - 1200;
end
end
My problem is I don't know how to build the function that defines "x" for step 1 so that the piecewise can be useful.

サインインしてコメントする。

### 回答 (1 件)

Sargondjani 2021 年 9 月 20 日
The script of your professor is actually the function. Save it and you can call the function.
function handle:
myfun = @(x)momentfunctionarray(x)
but there is really no point in doing this.
You can for example evaluate a function with argument x as follows:
x=linspace(0:0.01:20);
y = myfun(x);
You should look into the example of fplot and fzero to find out how to get those things.
##### 1 件のコメント-1 件の古いコメントを表示-1 件の古いコメントを非表示
Ezekiel Lawrence 2021 年 9 月 20 日
I see now, Thank you greatly, and I will go review fplot and fzero.

サインインしてコメントする。

### カテゴリ

Help Center および File ExchangeAssembly についてさらに検索

R2019a

### Community Treasure Hunt

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

Start Hunting!

Translated by