필터 지우기
필터 지우기

How can I multiply equation with number

조회 수: 2 (최근 30일)
Eman Ahmed Elsayed
Eman Ahmed Elsayed 2011년 5월 31일
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

채택된 답변

daniel.x16
daniel.x16 2011년 5월 31일
put a dot (.) before the * sign.
i.e. f=a.*func
  댓글 수: 3
Eman Ahmed Elsayed
Eman Ahmed Elsayed 2011년 5월 31일
no that's solved the problem
Walter Roberson
Walter Roberson 2011년 5월 31일
I doubt that. All that would do is change the error message from being about 'mtimes' to being about 'times'.

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

추가 답변 (1개)

Walter Roberson
Walter Roberson 2011년 5월 31일
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.

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by