How can I multiply equation with number

2 visualizaciones (últimos 30 días)
Eman Ahmed Elsayed
Eman Ahmed Elsayed el 31 de Mayo de 2011
I need to multiply a number by an equation
function [result] = SA_1(func,lamda)
%UNTITLED Summary of this function goes here
% Detailed explanation goes here
syms a;
a=lamda;
f=a*func;
result=f;
end
when I run I get the following error
??? Undefined function or method 'mtimes' for input arguments of type 'function_handle'.
Error in ==> SA_1 at 6
f=a*func;
I need any help

Respuesta aceptada

daniel.x16
daniel.x16 el 31 de Mayo de 2011
put a dot (.) before the * sign.
i.e. f=a.*func
  3 comentarios
Eman Ahmed Elsayed
Eman Ahmed Elsayed el 31 de Mayo de 2011
no that's solved the problem
Walter Roberson
Walter Roberson el 31 de Mayo de 2011
I doubt that. All that would do is change the error message from being about 'mtimes' to being about 'times'.

Iniciar sesión para comentar.

Más respuestas (1)

Walter Roberson
Walter Roberson el 31 de Mayo de 2011
Your line "a=lambda" overwrites the "syms a" that was established on the line above. You probably do not need the "syms a".
What you probably want is
function [result] = SA_1(func,lamda)
result=@(x) lambda*func(x);
end
This will construct a new function handle that includes the multiplication.
Warning: you won't be able to differentiate the new function handle either. Only symbolic expressions can be differentiated by MATLAB, unless you write the differentiation yourself.

Categorías

Más información sobre Symbolic Math 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!

Translated by