Loop and Conditional statements

7 ビュー (過去 30 日間)
James Bowler
James Bowler 2021 年 10 月 7 日
コメント済み: Rik 2021 年 10 月 7 日
Create a 100 element vector of x. Calculate the value of y to the corresponding value of x using loop and conditional statements
  2 件のコメント
James Bowler
James Bowler 2021 年 10 月 7 日
been struggling with this for a bit now, some help would be appreciated
Rik
Rik 2021 年 10 月 7 日
You can find guidelines for posting homework on this forum here. If you have trouble with Matlab basics you may consider doing the Onramp tutorial (which is provided for free by Mathworks). If your main issue is with understanding the underlying concept, you may consider re-reading the material you teacher provided and ask them for further clarification.

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

回答 (1 件)

Walter Roberson
Walter Roberson 2021 年 10 月 7 日
x = linpace(0, L/2, 100);
mask = 0 <= x & x <= L/2;
y(mask) = 16 .* x(mask).^3 - 24 .* L .* x(mask).^2 etc
y(~mask) = 8 .* x(mask).^3 - 24 .* L .* x(mask).^2 etc
  2 件のコメント
James Bowler
James Bowler 2021 年 10 月 7 日
Thanks for the help, it is required to use conditional statements and loops
Rik
Rik 2021 年 10 月 7 日
Easy to satify that requirement:
for n=1
if true
x = linpace(0, L/2, 100);
mask = 0 <= x & x <= L/2;
y(mask) = 16 .* x(mask).^3 - 24 .* L .* x(mask).^2 etc
y(~mask) = 8 .* x(mask).^3 - 24 .* L .* x(mask).^2 etc
end
end

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

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by