Hi there, I'm having some issues with logic functions in matlab. I don't use them very much so I'm not too familiar. What I'm trying to do is create an 'm' file for a physics project and I would like a certain progression. I'm trying to create some 'if' statements to do this. So first of all I guess is it possible, second, am I going about it correctly, third, if so then what do I need to change.(adsbygoogle = window.adsbygoogle || []).push({});

I want to set it up so when the user runs the file they can go to do some calculations or go to the homework assignment(I'm not this far yet). I've been playing around with if / elseif and I have it runnable but for example after the first part runs it prompts the user before displaying the homework. The prompt asks for the string 'start' but will accept anything. Is it possible to make it only accept start? If so how, this will basically allow me to finish it how I want with out other issues.

My goal in the end is to allow it to go to homework on string homework or calculations on string fun. This is the part I haven't really started yet because I've been trying to get the logic operators working correctly. It seems like this should be do-able but I don't know. Below is the copy of commands I've been working with. Copy and paste if needed (unless you're a crazy wiz) and I tested it just now and it works. What do I add / change? Also I know that at the end of the elseif it needs to be connected to the rest of the program but since I don't know how to do the first part I'm waiting on that.

Thanks so much everyone I know this was a long post. I really want to blow my class out of the water with this though! :)

mass_1=100000;%mass of space shuttle in kg

mass_2=(5.98*10^24);%mass of earth in kg

grav_const=(6.67*10^-11);

earth_radius=(6.37*10^6);%meters

orbit_alt=210;%miles on average

grav_accel=9.81;%m/s^2

prob_1=earth_radius+(orbit_alt*1609.344);

orbital_velocity=sqrt(prob_1*grav_accel);

% For fun

disp(' ')

disp('For fun')

disp(' ')

disp('To calculate potential energy enter the following masses in kg')

potential=-grav_const*(input('Enter what mass to use ')*input('Enter second objects mass '))/earth_radius;%potential energy "U"

fprintf(1,'The object''s potential energy is %g N/m \n',potential)

disp(' ')

disp('To calculate kinetic energy of an object enter the following mass in kg and velocity in m/s')

kinetic=.5*(input('Enter what mass to use ')*(input('Enter what velocity to use ')^2));

fprintf(1,'The object''s kinetic energy is %g N/m \n',kinetic)

disp(' ')

disp('To begin the homework follow instructions')

if(input('When ready, type ''start'' to begin ','s'))

% 1-distance from cener of earth

fprintf(1,'The distance of the space shuttle from the center of the earth is %d meters \n',prob_1)

% 2- Using forces, calculate the velocity of the shuttle required to

% maintain a circular orbit.

fprintf(1,'The speed required to maintain circular orbit at 210 miles is %f m/s \n',orbital_velocity)

elseif(input('Please type ''start''','s'))

end

**Physics Forums | Science Articles, Homework Help, Discussion**

Join Physics Forums Today!

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

# Matlab logic help

**Physics Forums | Science Articles, Homework Help, Discussion**