how do I code the following functions?
2 次查看(过去 30 天)
显示 更早的评论
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 个评论
Steven Lord
2021-11-1
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.
采纳的回答
M.MUSBA Elhadid
2021-11-1
Firstly,you have to write the mathematical expressions using Matlab Fundamentals. Then plot the results using plot Gallery too.
4 个评论
Walter Roberson
2021-11-1
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
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Graphics Performance 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!