Can someone check my code?
Afficher commentaires plus anciens
I am suppose to create a function m file called myminimum(f,a,b) which takes three inputs:
f: A function handle.
a: A real number.
b: A real number.
Note: You may assume that f(x) is a quadratic function and that a < b.
Does: Finds the minimum value of f(x) on [a, b] keeping in mind that this may occur either at the
critical point (if the critical point is in [a, b]) or at one of the endpoints. You’ll probably
want to use some if statements to check cases.
Returns: The minimum value of f(x) on [a, b].
Here is my code:
function m=myminimum (f,a,b);
syms x;
y=subs(f(x),a);
z=subs(f(x),b);
w=subs(diff(f(x)),0);
m=min(y,z,w);
end
It keeps returning an error. The error says "MIN with two matrices to compare and a working dimension is not supported." Can someone tell me how to fix my code?
Here is some sample data and the correct answers to the same code.
a= myminimum(@(x) x^2+1,-3,2)
a = 1
a = myminimum(@(x) x^2+6*x-3,-2,0)
a = -11
a = myminimum(@(x) -2*x^2+10*x,3,8)
a = -48
Réponse acceptée
Plus de réponses (2)
siham boujrad
le 11 Mai 2019
0 votes
%This program computes to calculate the Total Resistance (or Impedance) for Series or Parallel Circuit.
R1=input('Enter the value of R1'); %ohms
R2=input('Enter the value of R2'); %ohms
R3=input('Enter the value of R3'); %ohms
R=[R1,R2,R3];
RTs=sum(R);
RTp=1/sum(1./R);
If RTs>=5 & RTs<25
fprintf('Resistors are in series and R_Total = %7.2f ohms \n',RTs)
elseif RTp>0 & RTp<=1
fprintf('Resistors are in parallel and R_Total = %7.2f ohms \n',RTp)
else disp('Error')
endif
siham boujrad
le 11 Mai 2019
0 votes
plz i need someone to check the code for me. Thank you
Catégories
En savoir plus sur Operations on Strings dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!