Help creating a basic function

조회 수: 1 (최근 30일)
Michael Vaughan
Michael Vaughan 2020년 9월 24일
답변: Star Strider 2020년 9월 24일
So I already created the following script:
function [n] = n(x)
syms q
[n]=(q^(x/2)-q^(-x/2))/(q^(1/2)-q^(-1/2))
end
Which is working great!! I now want another function that has 2 inputs, x and y, and then outputs n(x+y+1)
Can somebody help me write this? I'm having trouble figuring this one out

답변 (1개)

Star Strider
Star Strider 2020년 9월 24일
It is likely easiest to define a third variable, then set that equal to what you want:
function [n] = n(x,y)
z = x+y+1;
syms q
n = (q^(z/2)-q^(-z/2))/(q^(1/2)-q^(-1/2))
end
For:
x = 3;
y = 10;
the result is:
n =
(1/q^7 - q^7)/(1/q^(1/2) - q^(1/2))
.

카테고리

Help CenterFile Exchange에서 Calculus에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by