# how do I code the following functions?

4 Ansichten (letzte 30 Tage)
Manah Bashour am 1 Nov. 2021
Kommentiert: Manah Bashour am 1 Nov. 2021
Hi everyone,
I have the following task to graph but I am still learining Matlab, could anyone help me with the code. I would really appreciate it. Thank you.
##### 1 Kommentar-1 ältere Kommentare anzeigen-1 ältere Kommentare ausblenden
Steven Lord am 1 Nov. 2021
This sounds like a homework assignment. If it is, show us the code you've written to try to solve the problem and ask a specific question about where you're having difficulty and we may be able to provide some guidance.
If you aren't sure where to start because you're not familiar with how to write MATLAB code, I suggest you start with the free MATLAB Onramp tutorial (https://www.mathworks.com/support/learn-with-matlab-tutorials.html) to quickly learn the essentials of MATLAB.
If you aren't sure where to start because you're not familiar with the mathematics you'll need to solve the problem, I recommend asking your professor and/or teaching assistant for help.

Melden Sie sich an, um zu kommentieren.

### Akzeptierte Antwort

M.MUSBA Elhadid am 1 Nov. 2021
Firstly,you have to write the mathematical expressions using Matlab Fundamentals. Then plot the results using plot Gallery too.
##### 4 Kommentare2 ältere Kommentare anzeigen2 ältere Kommentare ausblenden
Walter Roberson am 1 Nov. 2021
In order to use full functions without passing p in, you need to use shared variables, which are a more advanced topic.
In the below, in order for p to work correctly, it is important that the functions be defined inside the outer function.
Notice that I renamed the functions. You were using f as the name of all three functions, but f is some other function.
Notice that I changed all of the / to ./ as it is likely that your functions will be called with vector parameters.
You might notice that this does not plot anything: you did not call the functions anywhere to plot them.
(And you will need to have a definition for f in order to get anywhere(
Note: you were probably expected to use anonymous functions instead of full functions. If you had used anonymous functions, then it would not be necessary to use nested functions with shared variables.
hw2817; %needed to invoke the function that contains the nested functions
function hw2817
p = 0.25;
phi2 = 1;
function thetaC_res = phi__c(phi1, phi2)
thetaC_res = (p-f(phi2, 1-p))./(p-f(phi1, 1-p))
end
function thetaPrime_res = phi__prime(phi1, phi2)
thetaPrime_res = (p-f(phi2, 1-p))./(f(phi1,p)-f(phi1, 1-p))
end
function thetaFSquarde_res = phi__f2(phi1, phi2)
thetaFSquarde_res = (f(phi2, 1-p) - f(1- phi2, 1-p))./(f(phi1,p)-f(phi1,1-p))
end
end
Manah Bashour am 1 Nov. 2021
Thank you very much for your reply. ok, and now how can I plot these functions in one graph as required in my original post?
Thanks in advance for any help

Melden Sie sich an, um zu kommentieren.

### Kategorien

Mehr zu Graphics Performance finden Sie in Help Center und File Exchange

### Community Treasure Hunt

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

Start Hunting!

Translated by