How to write a function of a curve?

6 views (last 30 days)
jljl
jljl on 28 Aug 2012
Commented: Walter Roberson on 9 Apr 2020
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!

Accepted Answer

Friedrich
Friedrich on 28 Aug 2012
Edited: Friedrich on 28 Aug 2012
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 Comments
CS
CS on 8 Apr 2020
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
Walter Roberson on 9 Apr 2020
The code is only designed for scalar u, and would require significant rewrites for nonscalar u.

Sign in to comment.

More Answers (0)

Categories

Find more on Get Started with Curve Fitting Toolbox in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!