How to assign a variable based on an equation?

조회 수: 48 (최근 30일)
Matthew Carragher
Matthew Carragher 2021년 9월 12일
댓글: darova 2021년 9월 13일
I need to update certain material properties as a system cools. The properties are dependant on temperature, and I have equations that relate the values of the properties to temperature.
Is there a way to store an equation of a single variable, then use that equation to determine the value for a new variable?
I want to be able to define the equation at the start of the code and use that equation to determine the new property.
Something along the lines of:
Density_equation = x^2 + 2x + 10
T = 1000
Density = Density_equation(T)
I hope this makes sense, I am having trouble articulating my question.

답변 (1개)

Paul Hoffrichter
Paul Hoffrichter 2021년 9월 12일
Inline anonymous functions can be defined as follows:
Density_equation = @(x) x^2 + 2*x + 10
Density_equation = function_handle with value:
@(x)x^2+2*x+10
T = 1000
T = 1000
Density = Density_equation(T)
Density = 1002010
  댓글 수: 2
Matthew Carragher
Matthew Carragher 2021년 9월 13일
Thank You! Exactly what I needed!
darova
darova 2021년 9월 13일

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

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by