Hello,
I have an equation that I want to give to matlab :
I've tried to write it in matlab but it doesn't work. here is the code I've wrote :
function Hw = funTn(n,w)
%UNTITLED2 Summary of this function goes here
% Detailed explanation goes here
Tnw = ((((-2)^n)* factorial(n))/factorial(2*n))*sqrt(1-(w^2))*diff(((sqrt(1-(w)^2))^(2*n-1)),w,n);
Hw=abs(1/(sqrt(1+(Tnw)^2)));
end
please help me to correct this function for the given n and w in the formula above to plot the outputs.
Thank you

댓글 수: 1

David Hill
David Hill 2020년 4월 7일
편집: David Hill 2020년 4월 7일
Isn't H a function of n and w? How do you want the H output (in a matrix based on the values of n and w)? I assume you want just a numerical solution.

댓글을 달려면 로그인하십시오.

 채택된 답변

Ameer Hamza
Ameer Hamza 2020년 4월 7일

2 개 추천

First, since w is a vector, you should be using element-wise multiplication (.*). Second, you cannot use diff() on a numerical vector and expect it to be of the same size as before. To make the function, you first need some symbolic manipulation. Run this code
syms n w
Tnw = ((((-2)^n)* factorial(n))/factorial(2*n))*sqrt(1-(w^2))*diff(((sqrt(1-(w)^2))^(2*n-1)),w,n);
Hw = abs(1/(sqrt(1+(Tnw)^2)));
Hw_fun = matlabFunction(Hw, 'Vars', [n w]);
W = linspace(0,10,100);
n = 1:7;
H = zeros(numel(n), numel(W));
for i=1:size(H,1)
H(i,:) = Hw_fun(n(i), W);
end
fig = figure();
ax = axes();
hold(ax);
view(3);
grid on
ax.ZAxis.Scale = 'log';
for i=1:size(H,1)
plot3(W, n(i)*ones(size(W)), H(i,:));
end

댓글 수: 2

Evergreen Yellow
Evergreen Yellow 2020년 4월 7일
Thank you dear Ameer Hamza;
This is exactly what I was looking for. I really appreciate your help. It works like a charm.
YOU ARE THE BEEEEST !!!
Ameer Hamza
Ameer Hamza 2020년 4월 8일
Glad to be of help.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Creating, Deleting, and Querying Graphics Objects에 대해 자세히 알아보기

제품

릴리스

R2018b

태그

질문:

2020년 4월 7일

댓글:

2020년 4월 8일

Community Treasure Hunt

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

Start Hunting!

Translated by