How to set a function for error propagation

5 次查看(过去 30 天)
Hey, this is kinda my first try with
function
My aim is to code an automatic sequence for error propagation. E.g.
function [DeltaY] = equation(x)
With DeltaY being the solution and x an equation like x = a*b
As I said I have very little experience with functions, hence:
function [DeltaY] = equation(x)
DeltaY = sqrt((diff x,a)^2 * da^2 + (diff x,b)^2 * db^2)
end
does not work if I typ
equation(x)
Strikes me as I need to define a b da db seperately like
syms a b da db
x = a*b
But where to put it?

采纳的回答

SAA
SAA 2020-7-21
Yes you need to deinfe a b da and db either in the function or in your script before you call the function and also let them be inputs to your function
like this:
function [DeltaY] = equation(x,a,b,da,db)
DeltaY = sqrt((diff x,a)^2 * da^2 + (diff x,b)^2 * db^2)
end
  1 个评论
Niklas Kurz
Niklas Kurz 2020-7-24
编辑:Niklas Kurz 2020-7-24
One question is bothering me concering my code:
function [DeltaY] = equation(a, b, da, db)
DeltaY = sqrt(diff(((a+b)/(b-a)),a)^2 * da^2 + diff(((a+b)/(b-a)),b)^2 * db^2);
end
It works quite well, but as long as I define a,b,da,db Matlab won't derive anymore. For example
equation(1, 2, 0.1, 0.1)
gives:
ans = []
How to tell Matlab to set in values after it derived? Is this only possible with
subs()

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Function Creation 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by