How to write a function of a curve?
6 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
jljl
el 28 de Ag. de 2012
Comentada: Walter Roberson
el 9 de Abr. de 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!
0 comentarios
Respuesta aceptada
Friedrich
el 28 de Ag. de 2012
Editada: Friedrich
el 28 de Ag. de 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 comentarios
CS
el 8 de Abr. de 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
el 9 de Abr. de 2020
The code is only designed for scalar u, and would require significant rewrites for nonscalar u.
Más respuestas (0)
Ver también
Categorías
Más información sobre Get Started with Curve Fitting Toolbox en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!