Ask your own question, for FREE!
Mathematics 18 Online
OpenStudy (raffle_snaffle):

matlab help please

OpenStudy (raffle_snaffle):

% 6.10 This problem requires you to generate temperature-conversion tables. % Use the following equatioins, which describe the relationships between % temperature in degrees Fahrenheit (Tf), degrees celcius (Tc), kelvin % (Tk), and degrees Rankine (Tr), respectively. % Tf = Tr - 459.67 degrees R % Tf = 9/5*Tc + 32 degrees F % Tr = 9/5*Tk % (a) Create a function called F_to_K that converts temperatures in % Fahrenheit to Kelvin. Use your function to generate a conversion table % for values from 0* to 200* F. Tf = 0:200; % Fehrenheit vector from zero to two-hundred c6p10a = FK(Tf); % called c6p10a = Tk, this formula is to use to find kelvins % table displays ouptut of F and K F_K = [Tf; c6p10a]' % (c) Create a function called C_to_F that converts temperature in Celsius % to Fahrenheit. Use your function to generate a conversion table from 0T* % to 100* C. Choose an appropriate spacing.

OpenStudy (raffle_snaffle):

function F_to_K = FK(k) % this function converts degrees Fahrenheit to Kelvin F_to_K = (5/9)*(k+459.67);

OpenStudy (raffle_snaffle):

The reason I named FK(Tf) c6p10a is because my instructor wants us to use his variable formatting.

OpenStudy (raffle_snaffle):

@jim_thompson5910

OpenStudy (raffle_snaffle):

part a @jim_thompson5910

jimthompson5910 (jim_thompson5910):

ok let me look it over

OpenStudy (raffle_snaffle):

okay

jimthompson5910 (jim_thompson5910):

does your teacher want you to create a separate m file for the function? or have you put the function inside this current m file?

OpenStudy (raffle_snaffle):

Formatting and the hw assignment

OpenStudy (raffle_snaffle):

I don't think he does base on the schedule, 2nd one

jimthompson5910 (jim_thompson5910):

`Unless there is a reason not to, begin each problem with the clear and clc commands` so don't forget about that

jimthompson5910 (jim_thompson5910):

hmm it makes no mention of functions

OpenStudy (raffle_snaffle):

okay, I won't. So how does my function look? I can't get it to run, says there is a problem with line c6p10a = Fk(Tf)

OpenStudy (raffle_snaffle):

Put look at hw 6 on schedule.

OpenStudy (raffle_snaffle):

Even look at the description of the problem 6.10, posted

jimthompson5910 (jim_thompson5910):

you mean this? `Turn in 3 function m-files: F_to_K.m, C_to_F.m,` `& temperature_conversions.m only. No hw5.m` `required. Use HW format reqmnts`

OpenStudy (raffle_snaffle):

Yes, so I won't turn in 6.10 coding. But I made them for my use.

jimthompson5910 (jim_thompson5910):

ok, so you'll need to make the m file `F_to_K.m` and name the function `F_to_K` the function name and the m file name must match up so matlab can find the right function from the right file. If there isn't a match, matlab will let you know with an error

jimthompson5910 (jim_thompson5910):

`c6p10a = FK(Tf); % called c6p10a = Tk, this formula is to use to find kelvins` this line is invalid because FK is the wrong function name.

OpenStudy (raffle_snaffle):

okay let me think about this for a bit.

OpenStudy (raffle_snaffle):

Yes, got it. Tf = 0:200; % Fehrenheit vector from zero to two-hundred c6p10a = F_to_K(Tf); % called c6p10a = Tk, this formula is to use to find kelvins % table displays ouptut of F and K F_K = [Tf; c6p10a ]'

jimthompson5910 (jim_thompson5910):

looks good

OpenStudy (raffle_snaffle):

okay so F_to_k(Tf) has to match the F_to_K m file? What part needs to match?

jimthompson5910 (jim_thompson5910):

F_to_k is the name of the function it MUST match the name of the m file exactly. One character off and matlab won't be able to find the proper file

jimthompson5910 (jim_thompson5910):

so if your teacher wants you to call the m file `F_to_k.m` then you must name the function `F_to_k`

OpenStudy (raffle_snaffle):

Yes, I agree with the statement above. What about under 6.10? I called it homework5 so it's homework5.m

jimthompson5910 (jim_thompson5910):

on the line `c6p10a = FK(Tf);` you're calling some function `FK` which matlab will look through the directories (it is told to look through) for the m file `FK.m` but it may not find it. If it does find it, you may be looking in the wrong m file

OpenStudy (raffle_snaffle):

okay I see what you are saying now. Than answers my question.

jimthompson5910 (jim_thompson5910):

did you make a function called homework5?

OpenStudy (raffle_snaffle):

No, I didn't make a function called homework 5. My understanding is that I need the m file homework5 because that is where I put my vector and the table formula. ALso I need homework5 m file so I can ouput the conversions.

jimthompson5910 (jim_thompson5910):

I see

OpenStudy (raffle_snaffle):

I may email my instructor to double check with him as to whether or not he wants a homework5 m file. There is a possibility he wants just the function m files because he has the other information from each problem.

OpenStudy (raffle_snaffle):

Basically I had to make homework5 m file to see if my functions work.

jimthompson5910 (jim_thompson5910):

I think your prof is looking for only the function files. Since it says `No hw5.m required` but you'll still need your hw5.m file to test out the functions to see if they work or not

OpenStudy (raffle_snaffle):

Okay I see. Sounds good. Thanks for your help. If I have any additional questions I will tag you.

OpenStudy (raffle_snaffle):

@jim_thompson5910 subfunctions? I have to re do problem 6.10 but use subfunctionns %% 6.15 In Problem 6.10 you were asked to create and use three different % temperature conversion functions, based on the following conversion % equations: % Tf = Tr - 459.67 degrees R % Tf = 9/5*Tc + 32 degrees F % Tr = 9/5*Tk % Recreate Problem 6.10 using nested subfunctions. The primary function % should be called temperature_conversions and should include the % subfunctions % F_to_k % C_to_R % C_to_F % Within the primary function use the subfunctions to: clc; clear % clears command and workspace window % (a) Generate a conversion table for values from 0*F to 200*F. Include a % column for temperature in Fahrenheit and Kelvin.

OpenStudy (raffle_snaffle):

So these subfunctions would be in the current m files I have for the two separate functions or do I need to make one m file with many function in it?

jimthompson5910 (jim_thompson5910):

here's an example of what your teacher wants http://www.mathworks.com/help/matlab/matlab_prog/local-functions.html

OpenStudy (raffle_snaffle):

Okay I will take a look at it and let me think about this.

jimthompson5910 (jim_thompson5910):

see attached. I took a screenshot of that page and I go over the example of where the function and subfunctions are (where they start and end)

jimthompson5910 (jim_thompson5910):

OpenStudy (raffle_snaffle):

@jim_thompson5910

OpenStudy (raffle_snaffle):

jimthompson5910 (jim_thompson5910):

let me think

OpenStudy (raffle_snaffle):

having a bit of a hard time figuring out the conv_table ? My understanding is that each function should output the conversion factor given Tf?

jimthompson5910 (jim_thompson5910):

no, what I think is supposed to happen is that you step 1) go from Fahrenheit to Celsius step 2) go from Celsius to Kelvin then you make a table with the x column being the Fahrenheit and y column being the Kelvin

jimthompson5910 (jim_thompson5910):

the subfunctions won't show what is going on. Only the final result is shown. This is to avoid clutter

OpenStudy (raffle_snaffle):

so what you are saying is only make two sub functions? It asks to make three sub functions?

OpenStudy (raffle_snaffle):

But I see what you are saying. Basically have the program do the math portion.

OpenStudy (raffle_snaffle):

Let me think about this some more and figure it out.

jimthompson5910 (jim_thompson5910):

hmm I guess Rankine has to be in there too. Tbh, this is the first time I've ever seen Rankine before

OpenStudy (raffle_snaffle):

Well I solved for Rankine on paper. So I am going to have 3 temp_conv m files for this part of the assignment?

jimthompson5910 (jim_thompson5910):

I think so

OpenStudy (raffle_snaffle):

I found the Rankine formula from the other two formulas

OpenStudy (raffle_snaffle):

Let me think about this

jimthompson5910 (jim_thompson5910):

where is your part b?

OpenStudy (raffle_snaffle):

part C, he asked us only to do part a and c % (c) Recall that you will need to call your primary function from the % command window or from a script M-file.

jimthompson5910 (jim_thompson5910):

ah ok

OpenStudy (raffle_snaffle):

I will figure this part out later

jimthompson5910 (jim_thompson5910):

Can I offer a suggestion? I noticed you wrote F_to_K as one of your variable names. That's a bit clunky. The ouptut of the FK function is the kelvin temperature, so why not just call the output K? Instead of F_to_K

jimthompson5910 (jim_thompson5910):

and there's a problem with your temperature_conversions function x is the input x is what exactly? The temperature in Celsius? The temperature in Fahrenheit?

OpenStudy (raffle_snaffle):

because I am a complicated person lol No, thanks for the suggestion. I will change it to K. Sometimes I am writing this code I just use what is available. Sometimes I have a hard time naming variables because I am trying to organize the info in my head so I just start using what ever variables sounds reasonable.

OpenStudy (raffle_snaffle):

Yes, I don't know what the x represents in the temperature_conversion(x) I am still trying to understand what x represents relating to the other variables like k, f, c

jimthompson5910 (jim_thompson5910):

F_to_K is better suited as a function (or subfunction) name

OpenStudy (raffle_snaffle):

Take for example this code function [avg, med] = mystats(x) n = length(x); avg = mymean(x,n); med = mymedian(x,n); end function a = mymean(v,n) % MYMEAN Example of a local function. a = sum(v)/n; end function m = mymedian(v,n) % MYMEDIAN Another example of a local function. w = sort(v); if rem(n,2) == 1 m = w((n + 1)/2); else m = (w(n/2) + w(n/2 + 1))/2; end end

jimthompson5910 (jim_thompson5910):

x is the input of the `temperature_conversions` function x gets fed into the FK, CR, CF subfunctions so there's a mismatch in units when you have Fahrenheit for the first subfunction but Celsius for the other subfunctions

jimthompson5910 (jim_thompson5910):

what's your question about that example?

OpenStudy (raffle_snaffle):

looking at a = mymean(v,n) this has v and n but no x

OpenStudy (raffle_snaffle):

it only has v and n in the formula a = sum(v)/n;

jimthompson5910 (jim_thompson5910):

so you're wondering why no x?

OpenStudy (raffle_snaffle):

How does that relate to function [avg, med] = mystats(x)

OpenStudy (raffle_snaffle):

yes

jimthompson5910 (jim_thompson5910):

well x is used but probably not in the way you think n is dependent on x n = length(x); gets the size of x (ie how many numbers we're dealing with)

jimthompson5910 (jim_thompson5910):

avg = mymean(x,n); calls the `mymean` function first input is x second input is n go to the definition of `mymean` and we see this line function a = mymean(v,n) so the first input is v, the second input is n match up the inputs v = x n = n

jimthompson5910 (jim_thompson5910):

so they could have said function a = mymean(x,n) but chose to go with v instead

OpenStudy (raffle_snaffle):

okay

OpenStudy (raffle_snaffle):

Okay so I need 3 temperature_conversions m files each function will have 1 to 2 subfunctions depending on how many equations are involved?

jimthompson5910 (jim_thompson5910):

I think you'll have 3 subfunctions based on what you wrote % Tf = Tr - 459.67 degrees R % Tf = 9/5*Tc + 32 degrees F % Tr = 9/5*Tk

OpenStudy (raffle_snaffle):

^So those are the sub functions? So then these equations are not sub functions % first subfunction FK function a = FK(f) a = (5 / 9) * (f + 459.67); end % second subfunction CR function b = CR(c1) b = (9 / 5) * (c1 + 273.15); end % third subfunction CF function c = CF(c2) c = (9 / 5) * (c2 + 32); end

OpenStudy (raffle_snaffle):

These are the equations that make the conversion

jimthompson5910 (jim_thompson5910):

hmm I'm still having an issue with how you set up the inputs

jimthompson5910 (jim_thompson5910):

let me think of how to fix that

OpenStudy (raffle_snaffle):

kk

jimthompson5910 (jim_thompson5910):

I think I may have something. One moment.

jimthompson5910 (jim_thompson5910):

ok I had to make two separate m files. I'm not sure how else to work it

OpenStudy (raffle_snaffle):

why not 3?

jimthompson5910 (jim_thompson5910):

here is the first one where the inputs are all in celsius

jimthompson5910 (jim_thompson5910):

take note how each subfunction has the same input: temp in Celsius

jimthompson5910 (jim_thompson5910):

well except the K_to_R one for some reason I forgot to delete it

jimthompson5910 (jim_thompson5910):

OpenStudy (raffle_snaffle):

brb I need to take care of something

jimthompson5910 (jim_thompson5910):

ok

OpenStudy (raffle_snaffle):

@jim_thompson5910

OpenStudy (raffle_snaffle):

Tf = 0:200; % Fehrenheit vector from zero to two-hundred c6p15a = temperature_conversions(Tf); % c6p15a = temp_conv which finds % these are the set of subfunctions that will be used to solve for kelvin % given fahrenheit % this function temperature_conversions has the input % of fahrenheit which will given rankine, then input rankine to get kelvin function [R, K] = temperature_conversions(Tf) R = F_to_R(Tf); K = R_to_K(Tf); end % function to solves for rankine given fahrenheit function R = F_to_R(F) R = F + 459.67; end % function solves for kelvin given rankine function K = R_to_K(R) K = (5/9)*R; end

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!