필터 지우기
필터 지우기

HELP need to run Chebyshev code!

조회 수: 2 (최근 30일)
Beata Dongwi
Beata Dongwi 2022년 9월 22일
댓글: Beata Dongwi 2022년 9월 22일
I have been trying to run the following code in MATLAB but to no avail. My version is really outdated. R2007b
%%Matlab code for Chebeval
clc
clear all
%all given x
x=linspace(-1,1,101);
%N=5;
N=5;
%chebeval matrix for given N
mat=chebeval(x,N);
%plotting all N=0 to 5
for i=1:N+1
str{i}=sprintf('N=%d',i-1);
hold on
plot(squeeze(mat(i,:)))
end
legend(str)
%function for chebeval
function mat=chebeval(x,N)
syms xx
T0(xx)=1+0*xx;
T1(xx)=xx;
mat(1,1:length(x))=ones(1,length(x));
mat(2,1:length(x))=T1(x);
for i=3:N+1
T2(xx)=2*xx*T1(xx)-T0(xx);
mat(i,1:length(x))=T2(x);
T0=T1;
T1=T2;
end
end
When I ran the code from the Editor window, I get the following message:
??? Error: File: ChebevalNUMAssignment1.m Line: 18 Column: 1
Function definitions are not permitted at the prompt or in scripts.
And if paste it and run it from the command window, I get the following message:
??? Undefined function or method 'chebeval' for input arguments of
type 'double'.
So, what should I do? Please help me, I tried so many times and I am new to MATLAB
  댓글 수: 5
Dyuman Joshi
Dyuman Joshi 2022년 9월 22일
@Beata Dongwi, even if you follow my instructions, you will get an error, as using syms() function requires symbolic toolbox.
Also, Symbolic toolbox (or any other toolbox for that matter) doesn't come inbuilt with MATLAB. You have to install a toolbox manually.
Beata Dongwi
Beata Dongwi 2022년 9월 22일
@Dyuman Joshi, I see what the problem is; I am busy installing a newer version now.
Thank you for taking out time to assist me. Very appreciated.

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

채택된 답변

Bjorn Gustavsson
Bjorn Gustavsson 2022년 9월 22일
Save your chebeval-function in a separate file chebeval.m. Then call that function from your script. For now you can put both script and function in the same working directory.
This way it becomes far easier to reuse the functions you write later on. That way you build up a set of tools which makes your programming incrementally stronger since you start to have tools to solve more complex problems later on, or at least tools that almost solves those problems and you only need to make smaller modifications to develop the new solution.
Once you've taken this step you will at some stage realize that it is preferable to organise your tools/functions in a better way and then you can group similar tools into toolboxes/different directories.
HTH
  댓글 수: 1
Beata Dongwi
Beata Dongwi 2022년 9월 22일
Thank you very much, I will try it right away

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

추가 답변 (0개)

카테고리

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

제품


릴리스

R2007b

Community Treasure Hunt

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

Start Hunting!

Translated by