Clear Filters
Clear Filters

Beginner question: Loops in Matlab

1 view (last 30 days)
Heartrin
Heartrin on 29 Oct 2015
Commented: Torsten on 29 Oct 2015
Hi all,
I need to write matlab codes for the below formula.
theta = u+h1-h2-w
in this formula,
h1 = (theta+8)*gamma*23; h2 = 8/(theta+1)
so its a loop which i have to write. All u,w,h1,h2,gamma is an array
how and what loop should i use to write a code for this problem?
  4 Comments
Torsten
Torsten on 29 Oct 2015
Why in a loop ? Do you want to calculate it iteratively ?
Best wishes
Torsten.
Heartrin
Heartrin on 29 Oct 2015
yes, all the variables in the formula is an array. i have to do it iteratively only right? or can i do it without a loop?

Sign in to comment.

Accepted Answer

Torsten
Torsten on 29 Oct 2015
Two solutions:
theta1=(1-(u-w)-9*23*gamma)./(2*(23*gamma-1))+sqrt(((1-(u-w)-9*23*gamma)./(2*(23*gamma-1))).^2-(-(u-w)-8*23*gamma+8)./(1-23*gamma))
theta2=(1-(u-w)-9*23*gamma)./(2*(23*gamma-1))-sqrt(((1-(u-w)-9*23*gamma)./(2*(23*gamma-1))).^2-(-(u-w)-8*23*gamma+8)./(1-23*gamma))
Best wishes
Torsten.
  2 Comments
Heartrin
Heartrin on 29 Oct 2015
thanks.
what if the equation is,
theta_dot = u+h1-h2-w
h1 = (theta+8)*gamma*23; h2 = 8/(theta+1)
theta_dot i mean its a dtheta/dt. then i have to use loop right?
Torsten
Torsten on 29 Oct 2015
I don't understand what you will try to do within a loop.
Use MATLAB's ode45 to solve your differential equations.
Best wishes
Torsten.

Sign in to comment.

More Answers (0)

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!