how to write a loop that finds the best fit value for each given input pair and plot all the resulted points?

4 visualizaciones (últimos 30 días)
I have t and vl observed data that i plotted first and then find the theoritical points and plot them in the same graph.
To construct the model to find the theoritical values i have to write a code according to following steps.
  1. select a starting pair for t1 and vl1. (in this case t=10 and vl = 3.61).
  2. Calculate A
  3. Calculate B
  4. Calculate A-B
  5. Test abs(A-B); if abs(A-B) < 0.001 stop, then go to 8. if not go to 6
  6. increment vl=vl+0.005
  7. goto 2.
  8. increment t=t+5
  9. goto 1
  10. finally plot each pair for A=B (approximately, within given tolerance)
Below is the draft loop I wrote but i am not sure how to actually make it work. Please help me.
for T=10; % tmax = 90;
for VL=3.61
A = atan((vs2.^2).*D2.*(sqrt(1-(VL.^2/vs2.^2)))./(vs1.^2.)*D1.*(sqrt(1-(VL.^2/vs1.^2))));
B = (((2.*pi.*z)./(VL.*T)).*(sqrt((VL.^2/vs1.^2)-1)));
while abs(A-B)<0.001
while abs(A-B)>=0.001
  6 comentarios
Anitha Limann
Anitha Limann el 14 de Oct. de 2021
Attached is the given question paper. I am supposed to use a value slightly higher than vs1 and lower than observed vL1.
Please see the attachment.

Iniciar sesión para comentar.

Respuesta aceptada

Mathieu NOE
Mathieu NOE el 15 de Oct. de 2021
hello Anitha
so yes there was a small bug in your equations
when you do the computation of A, you fliiped the terms
must be replaced by
that's the reason I got A complex numbers and not reals numbers because the ter under the square root was negative
I am still working on the code ....
  6 comentarios

Iniciar sesión para comentar.

Más respuestas (0)


Más información sobre Loops and Conditional Statements en Help Center y File Exchange.



Community Treasure Hunt

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

Start Hunting!

Translated by