How do I generate code Matlab to make my work easier

1 回表示 (過去 30 日間)
Yamina chbak
Yamina chbak 2021 年 1 月 12 日
コメント済み: Yamina chbak 2021 年 1 月 21 日
Hi, I hope you can help me for in this matter
i have a code to solve a problem and i want to change a value t and record the value of err
for example when t=0.1 , we get err=2.1542
when i change t=0.12, we get err=3.5475
when t=... we get err=......
So each
t=0.1, 0.12, 0.125, 0.1225, 0.13, 0.1345 ,.....0.15
Record how much the value of err to see plot(t,err) with t=[0.1 0.12 0.125 0.1225 ..0.15] and err=[2.1542; 3.5475; ...] Here is the problem record the value of err like a matrix
So how can write this ?
  2 件のコメント
David Hill
David Hill 2021 年 1 月 12 日
Easy, what is the equation for err?
Yamina chbak
Yamina chbak 2021 年 1 月 12 日
err is a norm L2: err=norm(abs(u_exact - u_num), 2). If i change the value of t, then u_num and u_exact are change

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

採用された回答

Walter Roberson
Walter Roberson 2021 年 1 月 12 日
tvals = [0.1 0.12 0.125 0.1225, 0.15];
numt = length(tvals);
err = zeros(1, numt);
for tidx = 1 : numt
t = tvals(tidx);
calculate err into variable
err(tidx) = appropriate result
end
plot(tvals, err)
  1 件のコメント
Yamina chbak
Yamina chbak 2021 年 1 月 21 日
Thanks you @Walter Roberson, It's working.
Thanks you again.

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

その他の回答 (0 件)

カテゴリ

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

製品

Community Treasure Hunt

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

Start Hunting!

Translated by