Borrar filtros
Borrar filtros

How to write a code for varying step size ?

14 visualizaciones (últimos 30 días)
revathy M
revathy M el 26 de Sept. de 2017
Comentada: Janet onoja el 4 de Abr. de 2023
Hi! I'm working on boundary layer theory.I've written a code for solving block tri-diagonal matrix.One of the variable i've taken with variable step size to get a good accuracy.Have used if loop .While executing it takes the first if condition and executes for the whole interval as my initialization is 0.As my incremental value is the varying parameter how to bring it?
x_bar=0;
if x_bar<=0.5
delx_bar=0.01;
elseif x_bar >=0.5 && x_bar <=1.25
delx_bar=0.005;
else
delx_bar=0.0001;
end
%%Intial profiles start
x_bar=0:delx_bar:1.25;
n_xbar=length(x_bar);
As I've used x_bar and length of x_bar in the code for calculation of values i need to define it. What changes do I have to make so that my x_bar values are generated first and then the successive delx_bar are taken for calculation of values.
  1 comentario
James Tursa
James Tursa el 26 de Sept. de 2017
What do you want for a result? A vector x_bar that starts at 0, then grows by 0.01 until it reaches the value 0.5, then grows by the value 0.005 until it reaches the value 1.25, then grows by 0.0001 until it reaches some final value?

Iniciar sesión para comentar.

Respuesta aceptada

Andrei Bobrov
Andrei Bobrov el 27 de Sept. de 2017
Editada: Andrei Bobrov el 27 de Sept. de 2017
Xb = [0, .5, 1.25, 2];
dx = [.01, .005, .0001];
x_bar = cumsum([Xb(1), repelem(dx,diff(Xb)./dx)]);
>> x_bar_j = 1.589
delx_bar_j = dx(discretize(x_bar_j,Xb))
x_bar_j =
1.589
delx_bar_j =
0.0001
>>
  2 comentarios
revathy M
revathy M el 27 de Sept. de 2017
Thank you.
Andrei Bobrov
Andrei Bobrov el 29 de Sept. de 2017
Hi Revathy!
If this answer solve problem from your question, please, "accept" him.

Iniciar sesión para comentar.

Más respuestas (3)

James Tursa
James Tursa el 26 de Sept. de 2017
Editada: James Tursa el 26 de Sept. de 2017
Does this do what you want? (Using arbitrary final value of 2.000 for example)
xstart = 0.000; xend = 0.500; dx = 0.01;
part1 = linspace(xstart ,xend,round((xend-xstart)/dx)+1);
xstart = 0.500; xend = 1.250; dx = 0.005;
part2 = linspace(xstart+dx,xend,round((xend-xstart)/dx) );
xstart = 1.250; xend = 2.000; dx = 0.0001;
part3 = linspace(xstart+dx,xend,round((xend-xstart)/dx) );
x_bar = [part1,part2,part3];
  4 comentarios
revathy M
revathy M el 27 de Sept. de 2017
Hi! Thank you. Will try .
revathy M
revathy M el 27 de Sept. de 2017
Hi! What's the difference between the above two syntax?

Iniciar sesión para comentar.


Suganthi D
Suganthi D el 7 de Oct. de 2021
Hi professor , a very happy morning. I have written a code for step input variation for 10 houses ..Time for 24 hours. But i do not is this correct or not.. I need your help .. Here I have attached the code .. I want the graph for 10 houses step variation at 24 hours.. how to write the code for tis one..
T=1:1:24; %hours
input = createStep('StepTime',5,'StepSize',5,'FinalTime',25)
plot(input);

AKASH KUMAR
AKASH KUMAR el 1 de Mzo. de 2022
clc
clear
close all
%% Variable step size
Step_0=2;
Step=Step_0;
ii=1;theta=0;
while true
theta= theta+Step;
th(ii)=(theta);
Y(ii)=sind(th(ii));
if Y(ii)>0.7 || Y(ii) <-0.7
Step=1/10*Step_0;
else
Step=Step_0;
end
ii=ii+1;
if theta>180*2
break
end
end
plot(th,Y,'.')
grid on;
xlabel('theta(deg)');
  1 comentario
Janet onoja
Janet onoja el 4 de Abr. de 2023
I having been trying to get code on variable step size using adams method but I can't. Any help please.

Iniciar sesión para comentar.

Categorías

Más información sobre Nonlinear Optimization en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by