Hi i need some help here to put this into a matlab

3 ビュー (過去 30 日間)
Mark Loui
Mark Loui 2021 年 3 月 26 日
コメント済み: Mark Loui 2021 年 3 月 26 日
Hi there i need some help please
How can i put these understanding into matlab form
while err<tol %I have other sets of code for this
the main thing is here
i like to put these understanding into a code form, without using a for loop as the while loop is to determine how many loops must it get
h=0.5;
a=0;
xnew=(a+h) %First
h=h/2
xnew2=(a+h a+2*h) %Second
h=h/2
xnew3=(a+h, a+2*h, a+4*h, a+6*h) %FOr every new xnew the element size is increase by multiple by 2 and the general form can be written as (a+h, a+2(n)*h) where n is 0,2,4,6,8
h=h/2
xnew4=(a+h, a+2*h, a+4*h, a+6*h, a+8*h, a+10*h, a+12*h, a+14*h)
h=h/2 %and the same set of code is to run until it satisfied the while loop
Please help and thank you in advance

採用された回答

KALYAN ACHARJYA
KALYAN ACHARJYA 2021 年 3 月 26 日
h=0.5;
a=0;
x=a+h;
i=2;
tol=...?
while err<tol
x=[x a+i*h];
h=h/2;
i=i+2;
err=..% Update
end
  1 件のコメント
Mark Loui
Mark Loui 2021 年 3 月 26 日
Hi there i cant call your codes as well, here are the codes i have used.
delete all;clear all;close all;
a=0;
b=1;
h=b-a;
x=a+(h/2);
i=2;
tol=1e-2;
err=0.1;
while err>tol
x(i)=[x a+i*h];
h=h/2;
i=i+2;
err=err-0.1;
end

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

その他の回答 (1 件)

David Hill
David Hill 2021 年 3 月 26 日
i=0;
while err<tol
xnew{i+1}=a+[h,h*2*(1:2^i-1)];%index into cell array (much better than different variable names)
h=h/2;
i=i+1;
err;%? not sure what you are doing here
end
  1 件のコメント
Mark Loui
Mark Loui 2021 年 3 月 26 日
Hi there i tried your method, it does not output for the xnew variable,
a=0;
b=1;
h=b-a;
err=0.1;
tol=1e-2;
i=0;
while err < tol
h=h/2;
xnew{i+1}=a+[h,h*2*(1:2^i-1)]
i=i+1;
err=err-0.1;
end
here are the codes that i use for the situation

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

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

製品


リリース

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by