function to call, code run but didnt print the value

x1=input('x1');
x2=input('x2');
x3=input('x3');
Xvec=[x1,x2,x3]';
function Fofx=my_fun1(R1;R2,R3)
R1=((2*Xvec(1)^2)(4*(Xvec(2))*(Xvec(3))*exp(Xvec(1))));
R2=(4*Xvec(1)^2)+(2*(Xvec(2)^2))+((Xvec(3)^2)*sin(Xvec(2)));
R3=(Xvec(1)*(Xvec(2)^2))-(4*Xvec(2)*(Xvec(3)^2)*cos(Xvec(1)));
Fofx=[R1;R2;R3]
end
The above program runs, but doesn't give the answer. It gives a warning:
my_fun1 might be unused.
Please help.

Réponses (1)

The code does not actually call ‘my_fun1’.
This version actually does —
% x1=input('x1');
% x2=input('x2');
% x3=input('x3');
% Xvec=[x1,x2,x3]';
Xvec = rand(3,1)
Xvec = 3×1
0.6603 0.3279 0.1597
FofX = my_fun1(Xvec)
FofX = 3×1
0.3535 1.9673 0.0446
function Fofx=my_fun1(Xvec)
R1=((2*Xvec(1)^2)*(4*(Xvec(2))*(Xvec(3))*exp(Xvec(1))));
% ↑ ← MISSING OPERATOR (Mulotiplicatiuon Assumed)
R2=(4*Xvec(1)^2)+(2*(Xvec(2)^2))+((Xvec(3)^2)*sin(Xvec(2)));
R3=(Xvec(1)*(Xvec(2)^2))-(4*Xvec(2)*(Xvec(3)^2)*cos(Xvec(1)));
Fofx=[R1;R2;R3];
end
I changed the argument to ‘my_fun1’ since that appeared to be appropriate.
Also, there was a missing operator that I supplied. Change that if I guessed wrong.
.

Catégories

En savoir plus sur Programming 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!

Translated by