MATLAB function within function handle output

Click For Summary

Discussion Overview

The discussion revolves around the implementation of a MATLAB function handle that outputs specific elements from a matrix generated by another function, "rockdynamicstage". Participants are exploring how to extract the last element of the fourth row for a range of input values (gama0) and how to structure the output appropriately for further analysis.

Discussion Character

  • Homework-related
  • Technical explanation
  • Debate/contested

Main Points Raised

  • One participant describes the need for the function handle "sim" to output the last element in the fourth row of the matrix produced by "rockdynamicstage" for various gama0 inputs.
  • Another participant suggests using a function handle "x" to achieve the desired output but does not clarify how to integrate it with the original requirements.
  • Some participants propose that modifying the "rockdynamicstage" function may be necessary to meet the requirements of the function handle.
  • There are suggestions to use a simple for loop to iterate over gama0 values, calling "sim" at each step, to collect the desired outputs.
  • Participants discuss the differences in code snippets presented, particularly regarding the use of the "get()" function, which is noted to be designed for objects and may not work as intended for matrix extraction.
  • There is uncertainty about whether the professor requires a specific architectural approach, with suggestions that simpler methods might suffice.

Areas of Agreement / Disagreement

Participants express differing views on the necessity of modifying the "rockdynamicstage" function and the best approach to implement the desired functionality. No consensus is reached on the optimal solution.

Contextual Notes

Participants note that the syntax and functionality of certain MATLAB commands, such as "get()", may not be suitable for the intended purpose, leading to further exploration of alternatives.

Carter
Messages
11
Reaction score
0

Homework Statement


MATLAB

The funciton "rockdynamicstage" outputs a matrix 4 by x, where x is somthing around 300( varies).

The funciton "rockdynamicstage" is within the funciton handle "sim" with an input of gama0. (PayMass,Masstages,Massfrac,Thstage,IspStage,ChangeTstage) ar parameters that are set earlier in the code.

sim= @(gama0) rockdynamicstage(gama0,PayMass,Masstages,Massfrac,Thstage,IspStage,ChangeTstage);

Homework Equations



I need the "sim" to output the last element in the 4th row of the "rockdynamicstage". So that I get the last element in the 4th row in "rockdynamicstage" for a range of gama0s.

How would I output it.

The Attempt at a Solution


I tried doing
sim= @(gama0) rockdynamicstage(gama0,PayMass,Masstages,Massfrac,Thstage,IspStage,ChangeTstage)(4,end);

similar to when using a regular matrix
 
Physics news on Phys.org
x= @(gama0) rockdynamicstage(gama0,PayMass,Masstages,Massfrac,Thstage,IspStage,ChangeTstage);
sim=x(4,end);

Or you can change the rockdynamicstage function
 
donpacino said:
x= @(gama0) rockdynamicstage(gama0,PayMass,Masstages,Massfrac,Thstage,IspStage,ChangeTstage);
sim=x(4,end);

Or you can change the rockdynamicstage function
But I need it to be a function handle. I need to be able to plug the function "sim" (that would ideally output the last element in the 4th row for a range of gama0s) into another function that finds the zero point.

So essentially I need the function handle to output a (x,2) array of the gama0s and the 4th row last elements for the rockdynamicstage.
output from the "sim" (or what you have as x) needs to be
[ gama01, rockdynamicstage(4,end); gama02, rockdynamicstage(4,end); gama03, rockdynamicstage(4,end);...so on]
 
well if you want to make it very complicated then you need to change rockdynamicstage
 
you can use a simple for loop to move between cases, calling sim at each gama value
 
This essentially is the outline but myrocketsim is rockdynamicstage. And the bisection method is used to find the zero
upload_2017-12-7_15-6-52.png
 

Attachments

  • upload_2017-12-7_15-6-52.png
    upload_2017-12-7_15-6-52.png
    20.1 KB · Views: 412
There is a key difference between the code you presented and the code in step 2
 
donpacino said:
There is a key difference between the code you presented and the code in step 2
What would that be?
 
Carter said:
What would that be?
Is it the "get()" part
 
  • #10
Yup
 
  • #11
I didn't realize get could extract elements of a matrix
 
  • #12
donpacino said:
I didn't realize get could extract elements of a matrix
that syntax "get()" doesn't work though
 
  • #13
get is designed to work with objects. My guess is you are supposed to define myrocket sim (or equivalent) as an object
 
  • #14
Do you know for sure that your professor requires this architecture. It could be done very easily by using a loop or modifying the function calls.

If not you need to modify the way your myrocketsim works
 

Similar threads

  • · Replies 10 ·
Replies
10
Views
2K
  • · Replies 13 ·
Replies
13
Views
3K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 10 ·
Replies
10
Views
3K
  • · Replies 12 ·
Replies
12
Views
2K
  • · Replies 4 ·
Replies
4
Views
7K
  • · Replies 1 ·
Replies
1
Views
7K
  • · Replies 4 ·
Replies
4
Views
5K
Replies
3
Views
4K
  • · Replies 22 ·
Replies
22
Views
3K