Info

此问题已关闭。 请重新打开它进行编辑或回答。

Why is my function not working?

1 次查看(过去 30 天)
Michael Vaughan
Michael Vaughan 2020-9-24
关闭: MATLAB Answer Bot 2021-8-20
I wrote this in a coding window:
function z = z(x)
z = (v^(x/2)-v^(-x/2))/(t^(x/2)-t^(-x/2));
end
then I saved it, went to the command prompt and typed z(3). I want my result to be:
(v^(3/2)-v^(-3/2))/(t^(3/2)-t^(-3/2))
But instead i get:
Error in z (line 2)
z = (v^(x/2)-v^(-x/2))/(t^(x/2)-t^(-x/2));
What is going wrong here? Thanks!

回答(2 个)

madhan ravi
madhan ravi 2020-9-24
编辑:madhan ravi 2020-9-24
syms v t % in the first line of function

Ameer Hamza
Ameer Hamza 2020-9-24
Because you haven't defined the values of v and t inside the function. Change to something like this
function z = z(x)
v = 1;
t = 2;
z = (v^(x/2)-v^(-x/2))/(t^(x/2)-t^(-x/2));
end

标签

Community Treasure Hunt

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

Start Hunting!

Translated by