Hi i need some help here to put this into a matlab
2 views (last 30 days)
Show older comments
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
0 Comments
Accepted Answer
KALYAN ACHARJYA
on 26 Mar 2021
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
More Answers (1)
David Hill
on 26 Mar 2021
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
See Also
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!