How to write a function of a curve?
조회 수: 6 (최근 30일)
이전 댓글 표시
Hi Everyone,
I'm trying to write a function which takes in 4 inputs, not x, and to return a curve as an output.
eg: f(x)= (1-x)^2
Is this possible? Without defining the variable x?
I'm new to Matlab and would appreciate any help, links or simple code to outline how this could be done.
Cheers!
댓글 수: 0
채택된 답변
Friedrich
2012년 8월 28일
편집: Friedrich
2012년 8월 28일
Hi,
try an anonymous function.
So for example
>> f = @(x,y,z,zz) x + y + z + zz
f =
@(x,y,z,zz)x+y+z+zz
>> f(1,2,3,4)
ans =
10
If your function is too complex, consider writing a function in a seperate m-file (save this in a file called f.m):
function out = f(x,y,z,zz)
out = x + y + z + zz
end
댓글 수: 9
CS
2020년 4월 8일
I didn't get to the curvepoint yet.
I want to give the values for u as
u=0:5
It gives the error "Unable to perform assignment because the left and right sides have a different number of elements.".
I want to draw on the same chart the 2 nd, 3rd, and 4th degree B-spline curves for the seven control points. Thus, the value for p would be 2, 3, and 4, for the 2nd, 3rd, and 4th degrees. Also, the value of u should be continous to be able to plot the curve. Considering u=0:5, MATLAB gave me the above error (as can be seen in the above functions, the value of u is specified at only one point.).
How should I solve these and plot the curves?
Appreciate your help!
Walter Roberson
2020년 4월 9일
The code is only designed for scalar u, and would require significant rewrites for nonscalar u.
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Get Started with Curve Fitting Toolbox에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!