How do i make this function write to the ode

1 view (last 30 days)
Hey Fellas
I have a issue with a function where i want to share the thrust and fuelin with a ode45. when i run the program it says
"Unrecognized function or variable 'thrust'.
Error in fdsafafdafda (line 33)
thrust_stage1=thrust*1000;"
isnt the function sharing the thrust via the outputargument? how do i make it work.
function tryss
menu('how much fuel and thrust do you want? ', 'Falcon 9', ' too much fuel ','Too little fuel', ' too little thrust', 'custom');
function [thrust,fuelin]=choice(menu)
if menu ==1
%standard Falcon 9
thrust=7607;
fuelin=423;
elseif menu ==2
thrust=7607;
fuelin=1000;
elseif menu ==3
thrust= 7607;
fuelin=40;
elseif menu ==4
thrust=1600;
fuelin=423;
elseif menu==5
thrust=input('kN thrust? ');
fuelin=input('tons of fuel? ');
end
end
thrust_stage1=thrust*1000;
fuel=fuelin*1000;
thrust_stage2=934000; %standard
tid=[0.1 1500];
SB = [0,0,0];
T=(1:1500);
opt = odeset('event', @analyse);
[t,y] = ode45(@(t,y) stage1(t,y,T,thrust_stage1, thrust_stage2,fuel),tid,SB,opt);
end

Accepted Answer

Jyotsna Talluri
Jyotsna Talluri on 22 Apr 2020
Here,you are not passing a valid input to the choice function.Pass the output from the menu function,the number of the chosen item to the choice function as below.
function tryss
ch = menu('how much fuel and thrust do you want? ', 'Falcon 9', ' too much fuel ','Too little fuel', ' too little thrust', 'custom');
[thrust,fuelin]=choice(ch);
thrust_stage1=thrust*1000;
fuel=fuelin*1000;
thrust_stage2=934000; %standard
tid=[0.1 1500];
SB = [0,0,0];
T=(1:1500);
opt = odeset('event', @analyse);
[t,y] = ode45(@(t,y) stage1(t,y,T,thrust_stage1, thrust_stage2,fuel),tid,SB,opt);
end
You need not define the function choice inside tryss.You can define in another .m file.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!

Translated by