Create a conditional function in script

Hello,
I'm trying to create a conditional equation in Matlab. I created a simple test script below and receive errors for "Missing or extra characters". In my test, I am trying to create a simple function "fun", where fun=2*R if R>0 and fun=3*R if R<=0.
close all
clear all
clc
syms R
fun(R)=
if R>0
2*R
elseif R<=0
3*R
end
It appears my approach is just incorrect. Any help is much appreciated.
Thanks!
Josh

1 件のコメント

Matt J
Matt J 2021 年 2 月 8 日
Does it have to be a symbolic function?

サインインしてコメントする。

回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeSymbolic Math Toolbox についてさらに検索

質問済み:

2021 年 2 月 7 日

コメント済み:

2021 年 2 月 8 日

Community Treasure Hunt

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

Start Hunting!

Translated by